1 | include "ASM/ASM.ma". |
---|
2 | include "ASM/Arithmetic.ma". |
---|
3 | include "ASM/Fetch.ma". |
---|
4 | include "ASM/Status.ma". |
---|
5 | include alias "basics/logic.ma". |
---|
6 | include alias "arithmetics/nat.ma". |
---|
7 | include "utilities/extralib.ma". |
---|
8 | |
---|
9 | (**************************************** START OF POLICY ABSTRACTION ********************) |
---|
10 | |
---|
11 | (* definition of & operations on jump length *) |
---|
12 | inductive jump_length: Type[0] ≝ |
---|
13 | | short_jump: jump_length |
---|
14 | | absolute_jump: jump_length |
---|
15 | | long_jump: jump_length. |
---|
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 |
---|
22 | let 〈upper, lower〉 ≝ vsplit ? 9 7 result in |
---|
23 | if get_index' ? 2 0 flags then |
---|
24 | 〈eq_bv 9 upper [[true;true;true;true;true;true;true;true;true]], true:::lower〉 |
---|
25 | else |
---|
26 | 〈eq_bv 9 upper (zero …), false:::lower〉. |
---|
27 | |
---|
28 | definition absolute_jump_cond: Word → Word → (*pseudo_instruction →*) |
---|
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〉. |
---|
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 ⇒ λ_. |
---|
232 | let b1_b2 ≝ vsplit ? 8 8 w in |
---|
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 ⇒ λ_. |
---|
384 | let v1_v2 ≝ vsplit ? 3 8 w in |
---|
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 ⇒ λ_. |
---|
392 | let v1_v2 ≝ vsplit ? 3 8 w in |
---|
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 ⇒ λ_. |
---|
402 | let b1_b2 ≝ vsplit ? 8 8 w in |
---|
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 ⇒ λ_. |
---|
410 | let b1_b2 ≝ vsplit ? 8 8 w in |
---|
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 |
---|
436 | qed. |
---|
437 | |
---|
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 |
---|
440 | the beginning. |
---|
441 | *) |
---|
442 | definition expand_relative_jump_internal: |
---|
443 | ∀lookup_labels:Identifier → Word.∀sigma:Word → Word. |
---|
444 | Identifier → Word → ([[relative]] → preinstruction [[relative]]) → |
---|
445 | list instruction |
---|
446 | ≝ |
---|
447 | λlookup_labels.λsigma.λlbl.λppc,i. |
---|
448 | let lookup_address ≝ sigma (lookup_labels lbl) in |
---|
449 | let pc_plus_jmp_length ≝ sigma (add … ppc (bitvector_of_nat … 1)) in |
---|
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 |
---|
454 | [ RealInstruction (i address) ] |
---|
455 | else |
---|
456 | [ RealInstruction (i (RELATIVE (bitvector_of_nat ? 2))); |
---|
457 | SJMP (RELATIVE (bitvector_of_nat ? 3)); (* LJMP size? *) |
---|
458 | LJMP (ADDR16 lookup_address) |
---|
459 | ]. |
---|
460 | % |
---|
461 | qed. |
---|
462 | |
---|
463 | definition expand_relative_jump: |
---|
464 | ∀lookup_labels.∀sigma. |
---|
465 | Word → (*jump_length →*) |
---|
466 | preinstruction Identifier → list instruction ≝ |
---|
467 | λlookup_labels: Identifier → Word. |
---|
468 | λsigma:Word → Word. |
---|
469 | λppc: Word. |
---|
470 | (*λjmp_len: jump_length.*) |
---|
471 | λi: preinstruction Identifier. |
---|
472 | (*let rel_jmp ≝ RELATIVE (bitvector_of_nat ? 2) in*) |
---|
473 | match i with |
---|
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) |
---|
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 ?) ] |
---|
511 | ]. |
---|
512 | |
---|
513 | definition expand_pseudo_instruction: |
---|
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. |
---|
521 | λppc. |
---|
522 | λlookup_datalabels:Identifier → Word. |
---|
523 | λi. |
---|
524 | match i with |
---|
525 | [ Cost cost ⇒ [ ] |
---|
526 | | Comment comment ⇒ [ ] |
---|
527 | | Call call ⇒ |
---|
528 | let pc_plus_jmp_length ≝ sigma (add … ppc (bitvector_of_nat … 1)) in |
---|
529 | let lookup_address ≝ sigma (lookup_labels call) in |
---|
530 | let 〈mj_possible, disp〉 ≝ absolute_jump_cond pc_plus_jmp_length lookup_address in |
---|
531 | let do_a_long ≝ policy ppc in |
---|
532 | if mj_possible ∧ ¬ do_a_long then |
---|
533 | let address ≝ ADDR11 disp in |
---|
534 | [ ACALL address ] |
---|
535 | else |
---|
536 | let address ≝ ADDR16 lookup_address in |
---|
537 | [ LCALL address ] |
---|
538 | | Mov d trgt ⇒ |
---|
539 | let address ≝ DATA16 (lookup_datalabels trgt) in |
---|
540 | [ RealInstruction (MOV ? (inl ? ? (inl ? ? (inr ? ? 〈DPTR, address〉))))] |
---|
541 | | Instruction instr ⇒ expand_relative_jump lookup_labels sigma ppc instr |
---|
542 | | Jmp jmp ⇒ |
---|
543 | let pc_plus_jmp_length ≝ sigma (add … ppc (bitvector_of_nat … 1)) in |
---|
544 | let do_a_long ≝ policy ppc in |
---|
545 | let lookup_address ≝ sigma (lookup_labels jmp) in |
---|
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 |
---|
549 | [ SJMP address ] |
---|
550 | else |
---|
551 | let 〈mj_possible, disp2〉 ≝ absolute_jump_cond pc_plus_jmp_length lookup_address in |
---|
552 | if mj_possible ∧ ¬ do_a_long then |
---|
553 | let address ≝ ADDR11 disp2 in |
---|
554 | [ AJMP address ] |
---|
555 | else |
---|
556 | let address ≝ ADDR16 lookup_address in |
---|
557 | [ LJMP address ] |
---|
558 | ]. |
---|
559 | % |
---|
560 | qed. |
---|
561 | |
---|
562 | definition assembly_1_pseudoinstruction ≝ |
---|
563 | λlookup_labels. |
---|
564 | λsigma: Word → Word. |
---|
565 | λpolicy: Word → bool. |
---|
566 | λppc: Word. |
---|
567 | λlookup_datalabels. |
---|
568 | λi. |
---|
569 | let pseudos ≝ expand_pseudo_instruction lookup_labels sigma policy ppc lookup_datalabels i in |
---|
570 | let mapped ≝ map ? ? assembly1 pseudos in |
---|
571 | let flattened ≝ flatten ? mapped in |
---|
572 | let pc_len ≝ length ? flattened in |
---|
573 | 〈pc_len, flattened〉. |
---|
574 | |
---|
575 | definition instruction_size ≝ |
---|
576 | λlookup_labels. |
---|
577 | λlookup_datalabels. |
---|
578 | λsigma: Word → Word. |
---|
579 | λpolicy: Word → bool. |
---|
580 | λppc. |
---|
581 | λi. |
---|
582 | \fst (assembly_1_pseudoinstruction lookup_labels sigma policy ppc lookup_datalabels i). |
---|
583 | |
---|
584 | (* Labels *) |
---|
585 | definition is_label ≝ |
---|
586 | λx:labelled_instruction.λl:Identifier. |
---|
587 | let 〈lbl,instr〉 ≝ x in |
---|
588 | match lbl with |
---|
589 | [ Some l' ⇒ l' = l |
---|
590 | | _ ⇒ False |
---|
591 | ]. |
---|
592 | |
---|
593 | lemma label_does_not_occur: |
---|
594 | ∀i:ℕ.∀p:list labelled_instruction.∀l:Identifier. |
---|
595 | is_label (nth i ? p 〈None ?, Comment [ ]〉) l → does_not_occur ?? l p = false. |
---|
596 | #i #p #l generalize in match i; elim p |
---|
597 | [ #i >nth_nil #H cases H |
---|
598 | | #h #t #IH #i cases i -i |
---|
599 | [ cases h #hi #hp cases hi |
---|
600 | [ normalize #H cases H |
---|
601 | | #l' #Heq whd in ⊢ (??%?); change with (eq_identifier ? l' l) in match (instruction_matches_identifier ????); |
---|
602 | whd in Heq; >Heq |
---|
603 | >eq_identifier_refl / by refl/ |
---|
604 | ] |
---|
605 | | #i #H whd in match (does_not_occur ????); |
---|
606 | whd in match (instruction_matches_identifier ????); |
---|
607 | cases h #hi #hp cases hi normalize nodelta |
---|
608 | [ @(IH i) @H |
---|
609 | | #l' @eq_identifier_elim |
---|
610 | [ normalize / by / |
---|
611 | | normalize #_ @(IH i) @H |
---|
612 | ] |
---|
613 | ] |
---|
614 | ] |
---|
615 | ] |
---|
616 | qed. |
---|
617 | |
---|
618 | definition sigma_policy_specification ≝ |
---|
619 | λprogram: pseudo_assembly_program. |
---|
620 | λsigma: Word → Word. |
---|
621 | λpolicy: Word → bool. |
---|
622 | sigma (zero …) = zero … ∧ |
---|
623 | let instr_list ≝ \snd program in |
---|
624 | let preamble ≝ \fst program in |
---|
625 | ∀ppc: Word. ∀ppc_ok: nat_of_bitvector … ppc < |instr_list|. |
---|
626 | let pc ≝ sigma ppc in |
---|
627 | let labels ≝ \fst (create_label_cost_map instr_list) in |
---|
628 | let lookup_labels ≝ λx. bitvector_of_nat 16 (lookup_def … labels x 0) in |
---|
629 | let lookup_datalabels ≝ λx. lookup_def … (construct_datalabels preamble) x (zero …) in |
---|
630 | let instruction ≝ \fst (fetch_pseudo_instruction instr_list ppc ppc_ok) in |
---|
631 | let next_pc ≝ sigma (add 16 ppc (bitvector_of_nat 16 1)) in |
---|
632 | next_pc = add 16 pc (bitvector_of_nat … (instruction_size lookup_labels lookup_datalabels sigma policy ppc instruction)) |
---|
633 | ∧ |
---|
634 | (nat_of_bitvector … pc + instruction_size lookup_labels lookup_datalabels sigma policy ppc instruction < 2^16 |
---|
635 | ∨ |
---|
636 | (∀ppc'. ∀ppc_ok':nat_of_bitvector … ppc' < |instr_list|. nat_of_bitvector … ppc < nat_of_bitvector … ppc' → |
---|
637 | let instruction' ≝ \fst (fetch_pseudo_instruction instr_list ppc' ppc_ok') in |
---|
638 | instruction_size lookup_labels lookup_datalabels sigma policy ppc' instruction' = 0) |
---|
639 | ∧ |
---|
640 | nat_of_bitvector … pc + instruction_size lookup_labels lookup_datalabels sigma policy ppc instruction = 2^16). |
---|
641 | |
---|
642 | |
---|
643 | lemma fst_assembly_1_pseudoinstruction_insensible_to_lookup_datalabels: |
---|
644 | ∀lookup_labels,sigma,policy,ppc,pi. |
---|
645 | ∀lookup_datalabels1,lookup_datalabels2. |
---|
646 | \fst (assembly_1_pseudoinstruction lookup_labels sigma policy ppc lookup_datalabels1 pi) = |
---|
647 | \fst (assembly_1_pseudoinstruction lookup_labels sigma policy ppc lookup_datalabels2 pi). |
---|
648 | #lookup_labels #sigma #policy #ppc #pi #lookup_datalabels1 #lookup_datalabels2 |
---|
649 | cases pi // |
---|
650 | qed. |
---|
651 | |
---|
652 | lemma fst_snd_assembly_1_pseudoinstruction: |
---|
653 | ∀lookup_labels,sigma,policy,ppc,pi,lookup_datalabels,len,assembled. |
---|
654 | assembly_1_pseudoinstruction lookup_labels sigma policy ppc lookup_datalabels pi |
---|
655 | = 〈len,assembled〉 → |
---|
656 | len = |assembled|. |
---|
657 | #lookup #sigma #policy #ppc #pi #lookup_datalabels #len #assembled |
---|
658 | inversion (assembly_1_pseudoinstruction ??????) #len' #assembled' |
---|
659 | whd in ⊢ (??%? → ?); #EQ1 #EQ2 destruct % |
---|
660 | qed. |
---|
661 | |
---|
662 | (* XXX: easy but tedious *) |
---|
663 | lemma assembly1_lt_128: |
---|
664 | ∀i: instruction. |
---|
665 | |(assembly1 i)| < 128. |
---|
666 | cases daemon |
---|
667 | (* XXX: commented out as takes ages to type check |
---|
668 | #i cases i |
---|
669 | try (#assm1 #assm2) try #assm1 |
---|
670 | [8: |
---|
671 | cases assm1 |
---|
672 | try (#assm1 #assm2) try #assm1 |
---|
673 | whd in match assembly1; normalize nodelta |
---|
674 | whd in match assembly_preinstruction; normalize nodelta |
---|
675 | try @(subaddressing_mode_elim … assm2) |
---|
676 | try @(subaddressing_mode_elim … assm1) try #w try #w' normalize nodelta |
---|
677 | [32: |
---|
678 | cases assm1 -assm1 #assm1 normalize nodelta |
---|
679 | cases assm1 #addr1 #addr2 normalize nodelta |
---|
680 | [1: |
---|
681 | @(subaddressing_mode_elim … addr2) |
---|
682 | |2: |
---|
683 | @(subaddressing_mode_elim … addr1) |
---|
684 | ] |
---|
685 | #w |
---|
686 | |35,36,37: |
---|
687 | cases assm1 -assm1 #assm1 normalize nodelta |
---|
688 | [1,3: |
---|
689 | cases assm1 -assm1 #assm1 normalize nodelta |
---|
690 | ] |
---|
691 | cases assm1 #addr1 #addr2 normalize nodelta |
---|
692 | @(subaddressing_mode_elim … addr2) try #w |
---|
693 | |49: |
---|
694 | cases assm1 -assm1 #assm1 normalize nodelta |
---|
695 | [1: |
---|
696 | cases assm1 -assm1 #assm1 normalize nodelta |
---|
697 | [1: |
---|
698 | cases assm1 -assm1 #assm1 normalize nodelta |
---|
699 | [1: |
---|
700 | cases assm1 -assm1 #assm1 normalize nodelta |
---|
701 | [1: |
---|
702 | cases assm1 -assm1 #assm1 normalize nodelta |
---|
703 | ] |
---|
704 | ] |
---|
705 | ] |
---|
706 | ] |
---|
707 | cases assm1 #addr1 #addr2 normalize nodelta |
---|
708 | [1,3,4,5: |
---|
709 | @(subaddressing_mode_elim … addr2) try #w |
---|
710 | |*: |
---|
711 | @(subaddressing_mode_elim … addr1) try #w |
---|
712 | normalize nodelta |
---|
713 | [1,2: |
---|
714 | @(subaddressing_mode_elim … addr2) try #w |
---|
715 | ] |
---|
716 | ] |
---|
717 | |50: |
---|
718 | cases assm1 -assm1 #assm1 normalize nodelta |
---|
719 | cases assm1 #addr1 #addr2 normalize nodelta |
---|
720 | [1: |
---|
721 | @(subaddressing_mode_elim … addr2) try #w |
---|
722 | |2: |
---|
723 | @(subaddressing_mode_elim … addr1) try #w |
---|
724 | ] |
---|
725 | ] |
---|
726 | normalize repeat @le_S_S @le_O_n |
---|
727 | ] |
---|
728 | whd in match assembly1; normalize nodelta |
---|
729 | [6: |
---|
730 | normalize repeat @le_S_S @le_O_n |
---|
731 | |7: |
---|
732 | @(subaddressing_mode_elim … assm2) normalize repeat @le_S_S @le_O_n |
---|
733 | |*: |
---|
734 | @(subaddressing_mode_elim … assm1) #w normalize nodelta repeat @le_S_S @le_O_n |
---|
735 | ] |
---|
736 | *) |
---|
737 | qed. |
---|
738 | |
---|
739 | lemma assembly1_pseudoinstruction_lt_2_to_16: |
---|
740 | ∀lookup_labels,sigma,policy,ppc,lookup_datalabels,pi. |
---|
741 | |\snd (assembly_1_pseudoinstruction |
---|
742 | lookup_labels sigma policy ppc lookup_datalabels pi)| |
---|
743 | < 2^16. |
---|
744 | #lookup_labels #sigma #policy #ppc #lookup_datalabels * |
---|
745 | [ cut (128 < 2^16) [@leb_true_to_le %] #LT |
---|
746 | * whd in match (assembly_1_pseudoinstruction ??????); |
---|
747 | whd in match (expand_pseudo_instruction ??????); |
---|
748 | whd in match assembly_1_pseudoinstruction; normalize nodelta |
---|
749 | try (#arg1 #arg2 #arg3) try (#arg1 #arg2) try #arg1 |
---|
750 | whd in match (expand_pseudo_instruction ??????); |
---|
751 | try |
---|
752 | (change with (|flatten ? [assembly1 ?]| < ?) |
---|
753 | >flatten_singleton |
---|
754 | @(transitive_lt … (assembly1_lt_128 ?)) |
---|
755 | @LT) |
---|
756 | @pair_elim #x #y #_ cases x normalize nodelta |
---|
757 | try |
---|
758 | (change with (|flatten ? [assembly1 ?]| < ?) |
---|
759 | >flatten_singleton |
---|
760 | @(transitive_lt … (assembly1_lt_128 ?)) |
---|
761 | @LT) |
---|
762 | change with (|flatten ? [assembly1 ?; assembly1 ?; assembly1 ?]| < ?) |
---|
763 | >length_flatten_cons >length_flatten_cons >length_flatten_cons <plus_n_O |
---|
764 | <associative_plus @(transitive_lt … (tech_transitive_lt_3 … (2^7) ???)) |
---|
765 | try @assembly1_lt_128 @leb_true_to_le % |
---|
766 | |2,3: #msg normalize in ⊢ (?%?); // |
---|
767 | | #label whd in match (assembly_1_pseudoinstruction ??????); |
---|
768 | whd in match (expand_pseudo_instruction ??????); |
---|
769 | @pair_elim #sj_poss #disp cases (?∧?) normalize nodelta #_ |
---|
770 | [2: @pair_elim #x #y #_ cases (?∧?)] |
---|
771 | normalize in ⊢ (?%?); // |
---|
772 | | #label whd in match (assembly_1_pseudoinstruction ??????); |
---|
773 | whd in match (expand_pseudo_instruction ??????); |
---|
774 | @pair_elim #sj_poss #disp cases (?∧?) normalize nodelta #_ |
---|
775 | normalize in ⊢ (?%?); // |
---|
776 | | #dptr #id normalize in ⊢ (?%?); // |
---|
777 | ] |
---|
778 | qed. |
---|
779 | |
---|
780 | definition assembly: |
---|
781 | ∀p: pseudo_assembly_program. |
---|
782 | ∀sigma: Word → Word. |
---|
783 | ∀policy: Word → bool. |
---|
784 | Σres:list Byte × (BitVectorTrie costlabel 16). |
---|
785 | sigma_policy_specification p sigma policy → |
---|
786 | let 〈preamble,instr_list〉 ≝ p in |
---|
787 | |instr_list| ≤ 2^16 → |
---|
788 | let 〈assembled,costs〉 ≝ res in |
---|
789 | |assembled| ≤ 2^16 ∧ |
---|
790 | (nat_of_bitvector … (sigma (bitvector_of_nat … (|instr_list|))) = |assembled| ∨ |
---|
791 | sigma (bitvector_of_nat … (|instr_list|)) = zero … ∧ |assembled| = 2^16) ∧ |
---|
792 | let 〈labels_to_ppc,ppc_to_costs〉 ≝ create_label_cost_map instr_list in |
---|
793 | let datalabels ≝ construct_datalabels preamble in |
---|
794 | let lookup_labels ≝ λx. bitvector_of_nat ? (lookup_def … labels_to_ppc x 0) in |
---|
795 | let lookup_datalabels ≝ λx. lookup_def … datalabels x (zero ?) in |
---|
796 | ∀ppc. ∀ppc_ok:nat_of_bitvector … ppc < |instr_list|. |
---|
797 | let 〈pi,newppc〉 ≝ fetch_pseudo_instruction instr_list ppc ppc_ok in |
---|
798 | let 〈len,assembledi〉 ≝ |
---|
799 | assembly_1_pseudoinstruction lookup_labels sigma policy ppc lookup_datalabels pi in |
---|
800 | |assembledi| ≤ |assembled| ∧ |
---|
801 | ∀j:nat. ∀H: j < |assembledi|. ∃K. |
---|
802 | nth_safe ? j assembledi H = |
---|
803 | nth_safe ? (nat_of_bitvector … (add … (sigma ppc) (bitvector_of_nat ? j))) |
---|
804 | assembled K |
---|
805 | ≝ |
---|
806 | λp. |
---|
807 | λsigma. |
---|
808 | λpolicy. |
---|
809 | deplet 〈preamble, instr_list〉 as p_refl ≝ p in |
---|
810 | deplet 〈labels_to_ppc,ppc_to_costs〉 as eq_create_label_cost_map ≝ create_label_cost_map instr_list in |
---|
811 | let datalabels ≝ construct_datalabels preamble in |
---|
812 | let lookup_labels ≝ λx. bitvector_of_nat ? (lookup_def … labels_to_ppc x 0) in |
---|
813 | let lookup_datalabels ≝ λx. lookup_def … datalabels x (zero ?) in |
---|
814 | let 〈next_pc,revcode〉 ≝ pi1 … ( |
---|
815 | foldl_strong |
---|
816 | (option Identifier × pseudo_instruction) |
---|
817 | (λpre. Σppc_code:(Word × (list Byte)). |
---|
818 | sigma_policy_specification 〈preamble,instr_list〉 sigma policy → |
---|
819 | |instr_list| ≤ 2^16 → |
---|
820 | let 〈ppc,code〉 ≝ ppc_code in |
---|
821 | ppc = bitvector_of_nat … (|pre|) ∧ |
---|
822 | |code| ≤ 2^16 ∧ |
---|
823 | (nat_of_bitvector … (sigma ppc) = |code| ∨ |
---|
824 | sigma ppc = zero … ∧ |code| = 2^16 ∧ |
---|
825 | (|pre| < 2^16 → ∀ppc'. ∀ppc_ok':nat_of_bitvector … ppc' < |instr_list|. nat_of_bitvector … ppc ≤ nat_of_bitvector … ppc' → |
---|
826 | let instruction' ≝ \fst (fetch_pseudo_instruction instr_list ppc' ppc_ok') in |
---|
827 | instruction_size lookup_labels lookup_datalabels sigma policy ppc' instruction' = 0) |
---|
828 | ) ∧ |
---|
829 | ∀ppc'.∀ppc_ok'. |
---|
830 | (nat_of_bitvector … ppc' < nat_of_bitvector … ppc ∨ |pre| = 2^16) → |
---|
831 | let 〈pi,newppc〉 ≝ fetch_pseudo_instruction instr_list ppc' ppc_ok' in |
---|
832 | let 〈len,assembledi〉 ≝ |
---|
833 | assembly_1_pseudoinstruction lookup_labels sigma policy ppc' lookup_datalabels pi in |
---|
834 | |assembledi| ≤ |reverse … code| ∧ |
---|
835 | ∀j:nat. ∀H: j < |assembledi|. ∃K. |
---|
836 | nth_safe ? j assembledi H = |
---|
837 | nth_safe ? (nat_of_bitvector … (add … (sigma ppc') (bitvector_of_nat ? j))) (reverse … code) K) |
---|
838 | instr_list |
---|
839 | (λprefix,hd,tl,prf,ppc_code. |
---|
840 | let 〈ppc, code〉 ≝ pi1 … ppc_code in |
---|
841 | let 〈pc_delta, program〉 ≝ assembly_1_pseudoinstruction lookup_labels sigma policy ppc lookup_datalabels (\snd hd) in |
---|
842 | let new_ppc ≝ add ? ppc (bitvector_of_nat ? 1) in |
---|
843 | 〈new_ppc, (reverse … program @ code)〉) |
---|
844 | 〈(zero ?), [ ]〉) |
---|
845 | in |
---|
846 | 〈reverse … revcode, |
---|
847 | fold … (λppc.λcost.λpc_to_costs. insert … (sigma ppc) cost pc_to_costs) ppc_to_costs (Stub ??)〉. |
---|
848 | [ cases (foldl_strong ? (λx.Σy.?) ???) in p1; #ignore_revcode #Hfold #EQignore_revcode |
---|
849 | >EQignore_revcode in Hfold; #Hfold #sigma_pol_ok #instr_list_ok |
---|
850 | cases (Hfold sigma_pol_ok instr_list_ok) -Hfold * * #Hfold1 #Hfold4 #Hfold5 #Hfold3 whd |
---|
851 | <eq_create_label_cost_map whd % |
---|
852 | [2: #ppc #LTppc @Hfold3 >Hfold1 @(eqb_elim (|instr_list|) 2^16) |
---|
853 | [ #limit %2 @limit |
---|
854 | | #nlimit %1 >nat_of_bitvector_bitvector_of_nat_inverse try assumption |
---|
855 | @not_eq_to_le_to_lt assumption ] |
---|
856 | | >length_reverse % try assumption cases Hfold5 -Hfold5 |
---|
857 | [ #Hfold5 <Hfold5 % >Hfold1 % |
---|
858 | | * #Hfold51 #Hfold52 %2 <Hfold1 assumption ]] |
---|
859 | | * #sigma_pol_ok1 #_ #instr_list_ok % |
---|
860 | [ % % [%] // >sigma_pol_ok1 % ] |
---|
861 | #ppc' #ppc_ok' #abs @⊥ cases abs |
---|
862 | [#abs2 cases (not_le_Sn_O ?) [#H @(H abs2) | skip] |
---|
863 | |#abs2 change with (0 = S ?) in abs2; destruct(abs2) ] |
---|
864 | | #sigma_pol_ok cases sigma_pol_ok #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 |
---|
865 | #IH cases (IH ? instr_list_ok) [2: % assumption ] -IH |
---|
866 | * * #IH1 #IH2 #IH3 #IH4 |
---|
867 | cut (|prefix| < |instr_list|) |
---|
868 | [ >prf >length_append normalize <plus_n_Sm @le_S_S // ] #LT_prefix_instr_list |
---|
869 | cut (|prefix| < 2^16) |
---|
870 | [ @(lt_to_le_to_lt … (|instr_list|)) assumption ] #prefix_ok |
---|
871 | cut (nat_of_bitvector … ppc < |instr_list|) |
---|
872 | [ >IH1 >nat_of_bitvector_bitvector_of_nat_inverse assumption ] #ppc_ok |
---|
873 | cut (\snd hd = \fst (fetch_pseudo_instruction instr_list ppc ppc_ok)) |
---|
874 | [ >prf in ppc_ok; >IH1 >(add_zero … (bitvector_of_nat … (|prefix|))) |
---|
875 | >fetch_pseudo_instruction_append |
---|
876 | [ #ppc_ok whd in match fetch_pseudo_instruction; normalize nodelta |
---|
877 | whd in match (nth_safe ????); [ cases hd // | normalize // ] |
---|
878 | | <add_zero >nat_of_bitvector_bitvector_of_nat_inverse |
---|
879 | [ <prf assumption | assumption ] |
---|
880 | | skip |
---|
881 | | <prf assumption |
---|
882 | ]] #eq_fetch_pseudo_instruction |
---|
883 | lapply (fst_snd_assembly_1_pseudoinstruction … p2) #EQpc_delta |
---|
884 | cut (pc_delta < 2^16) |
---|
885 | [ >EQpc_delta |
---|
886 | @(eq_ind ?? (λp.λ_. |\snd p| < 2^16) ?? p2) |
---|
887 | @assembly1_pseudoinstruction_lt_2_to_16 ] #pc_delta_ok |
---|
888 | cut (pc_delta = instruction_size lookup_labels lookup_datalabels sigma policy ppc (\snd hd)) |
---|
889 | [ whd in match instruction_size; normalize nodelta |
---|
890 | >fst_assembly_1_pseudoinstruction_insensible_to_lookup_datalabels [ >p2 | skip] % ] |
---|
891 | #EQpc_delta2 |
---|
892 | cases (sigma_pol_ok2 … ppc_ok) |
---|
893 | <eq_fetch_pseudo_instruction <eq_create_label_cost_map <EQpc_delta2 |
---|
894 | #sigma_pol3 #sigma_pol4 |
---|
895 | % [ % [% ] ] |
---|
896 | [ >length_append normalize nodelta >IH1 @sym_eq @add_bitvector_of_nat |
---|
897 | | >length_append >length_reverse <EQpc_delta |
---|
898 | cases IH3 -IH3 |
---|
899 | [ #IH3 <IH3 >commutative_plus |
---|
900 | cases sigma_pol4 [ #LT @(transitive_le … LT) // | * #_ #EQ >EQ % ] |
---|
901 | | * * #IH3a #IH3b #IH3c >IH3b <EQpc_delta >EQpc_delta2 >eq_fetch_pseudo_instruction |
---|
902 | >IH3c try % assumption ] |
---|
903 | | >length_append >length_reverse |
---|
904 | cases IH3 -IH3 |
---|
905 | [ #IH3 <IH3 <EQpc_delta cases sigma_pol4 |
---|
906 | [ #LT %1 >sigma_pol3 >nat_of_bitvector_add |
---|
907 | [2: >nat_of_bitvector_bitvector_of_nat_inverse assumption] |
---|
908 | >nat_of_bitvector_bitvector_of_nat_inverse try assumption // |
---|
909 | | * #EQ1 #EQ2 %2 % |
---|
910 | [ lapply (eq_f … (bitvector_of_nat 16) … EQ2) <add_bitvector_of_nat_plus |
---|
911 | >bitvector_of_nat_inverse_nat_of_bitvector <sigma_pol3 #X >X % // |
---|
912 | | #LLT_prefix |
---|
913 | cut (S (nat_of_bitvector … ppc) < 2^16) |
---|
914 | [ >length_append in LLT_prefix; <plus_n_Sm <plus_n_O #LLT_prefix |
---|
915 | >IH1 >nat_of_bitvector_bitvector_of_nat_inverse assumption ] |
---|
916 | -LLT_prefix #LLT_prefix |
---|
917 | #ppc' #ppc_ok' #LEQ_newppc_ppc' whd >EQ1 try % |
---|
918 | @(lt_to_le_to_lt … LEQ_newppc_ppc') normalize nodelta |
---|
919 | >nat_of_bitvector_add >nat_of_bitvector_bitvector_of_nat_inverse // ]] |
---|
920 | | * * #IH5 #IH6 #IH7 %2 % [% ] |
---|
921 | [ normalize nodelta >sigma_pol3 >IH5 |
---|
922 | >add_commutative <add_zero >nat_of_bitvector_bitvector_of_nat_inverse try assumption |
---|
923 | >EQpc_delta2 >eq_fetch_pseudo_instruction >IH7 try % assumption |
---|
924 | | >IH6 <EQpc_delta >EQpc_delta2 >eq_fetch_pseudo_instruction >IH7 try % |
---|
925 | assumption |
---|
926 | | #LLT_prefix |
---|
927 | cut (S (nat_of_bitvector … ppc) < 2^16) |
---|
928 | [ >length_append in LLT_prefix; <plus_n_Sm <plus_n_O #LLT_prefix |
---|
929 | >IH1 >nat_of_bitvector_bitvector_of_nat_inverse assumption ] |
---|
930 | -LLT_prefix #LLT_prefix |
---|
931 | #ppc' #ppc_ok' #LEQ_newppc_ppc' whd @IH7 try assumption |
---|
932 | @(transitive_le … LEQ_newppc_ppc') normalize nodelta |
---|
933 | >nat_of_bitvector_add >nat_of_bitvector_bitvector_of_nat_inverse // ]] |
---|
934 | | #ppc' #LTppc' cases hd in prf p2 EQpc_delta2 eq_fetch_pseudo_instruction; #label #pi #prf #p2 |
---|
935 | #EQpc_delta2 #eq_fetch_pseudo_instruction #OR_lt_eq @(eq_bv_elim … ppc' ppc) |
---|
936 | [ #EQppc' >EQppc' in LTppc'; -ppc' >prf |
---|
937 | >IH1 #LTppc lapply LTppc |
---|
938 | >(add_zero … (bitvector_of_nat 16 (|prefix|))) in ⊢ (% → match % with [_ ⇒ ?]); |
---|
939 | >fetch_pseudo_instruction_append |
---|
940 | [3: @le_S_S @le_O_n |
---|
941 | |2: lapply LTppc; >(add_zero … (bitvector_of_nat 16 (|prefix|))) in ⊢ (% → ?); #H @H |
---|
942 | |4: <prf <p_refl in instr_list_ok; #H @H ] |
---|
943 | #LTppc' @pair_elim #pi' #newppc' #EQpair destruct(EQpair) <IH1 >p2 % |
---|
944 | [ >length_reverse >length_append >length_reverse // ] |
---|
945 | #j #LTj >nat_of_bitvector_add |
---|
946 | >nat_of_bitvector_bitvector_of_nat_inverse |
---|
947 | [2,4: @(lt_to_le_to_lt … LTj) <EQpc_delta @(transitive_le … pc_delta_ok) %2 % |
---|
948 | |3: @(lt_to_le_to_lt … (nat_of_bitvector … (sigma ppc) + pc_delta)) |
---|
949 | [ >EQpc_delta @monotonic_lt_plus_r assumption |
---|
950 | | cases sigma_pol4 |
---|
951 | [ #H @(transitive_le … H) %2 % |
---|
952 | | * #_ #EQ >EQ % ]]] |
---|
953 | >reverse_append >reverse_reverse |
---|
954 | cases IH3 -IH3 |
---|
955 | [ #IH3 >IH3 <(length_reverse … code) % |
---|
956 | [ >length_append @monotonic_lt_plus_r assumption |
---|
957 | | @nth_safe_prepend ] |
---|
958 | | * * #IH3a #IH3b #IH3c >IH3a @⊥ |
---|
959 | cut (|program| = 0) |
---|
960 | [ <EQpc_delta >EQpc_delta2 >eq_fetch_pseudo_instruction @IH3c // ] #EQprogram |
---|
961 | @(absurd ?? (not_le_Sn_O j)) <EQprogram assumption ] |
---|
962 | | #NEQppc' |
---|
963 | lapply (IH4 … LTppc') |
---|
964 | @pair_elim #pi' #newppc' #eq_fetch_pseudoinstruction |
---|
965 | @pair_elim #len' #assembledi' #eq_assembly_1_pseudoinstruction #IH |
---|
966 | cases (IH ?) -IH |
---|
967 | [2: %1 cases OR_lt_eq |
---|
968 | [ normalize nodelta #LT lapply LT >nat_of_bitvector_add |
---|
969 | [2: >nat_of_bitvector_bitvector_of_nat_inverse [2: //] |
---|
970 | cases (le_to_or_lt_eq … (? : nat_of_bitvector … ppc < 2^16)) |
---|
971 | [ #X <plus_n_Sm <plus_n_O @X |
---|
972 | | #abs @⊥ |
---|
973 | <(bitvector_of_nat_inverse_nat_of_bitvector … ppc) in LT; |
---|
974 | >add_overflow [2: <plus_n_Sm <plus_n_O assumption ] |
---|
975 | #abs' @(absurd … abs') normalize in ⊢ (? (??%)); |
---|
976 | @not_le_Sn_O |
---|
977 | | @(lt_to_le_to_lt … ppc_ok) assumption ]] |
---|
978 | >nat_of_bitvector_bitvector_of_nat_inverse [2: // ] |
---|
979 | <plus_n_Sm <plus_n_O #X lapply (le_S_S_to_le … X) -X #X |
---|
980 | cases (le_to_or_lt_eq … X) [//] #abs @⊥ |
---|
981 | lapply (eq_f … (bitvector_of_nat 16) … abs) |
---|
982 | >bitvector_of_nat_inverse_nat_of_bitvector |
---|
983 | >bitvector_of_nat_inverse_nat_of_bitvector #EQ |
---|
984 | @(absurd … EQ NEQppc') |
---|
985 | | >length_append <plus_n_Sm <plus_n_O #EQ @le_S_S_to_le >IH1 |
---|
986 | >nat_of_bitvector_bitvector_of_nat_inverse try assumption |
---|
987 | cases (le_to_or_lt_eq … (lt_nat_of_bitvector 16 ppc')) [#X >EQ @X] |
---|
988 | #abs @⊥ <EQ in abs; #X lapply (injective_S … X) #abs |
---|
989 | lapply (eq_f … (bitvector_of_nat 16) … abs) |
---|
990 | >bitvector_of_nat_inverse_nat_of_bitvector <IH1 #EQ |
---|
991 | @(absurd … EQ NEQppc') ]] |
---|
992 | #IH6 #IH |
---|
993 | change with (let 〈len,assembledi〉 ≝ assembly_1_pseudoinstruction ????? pi' in ? ∧ ∀j:ℕ. ∀H:j<|assembledi|.?) |
---|
994 | >eq_assembly_1_pseudoinstruction % |
---|
995 | [ >reverse_append >length_append |
---|
996 | >(fst_snd_assembly_1_pseudoinstruction … eq_assembly_1_pseudoinstruction) |
---|
997 | @(transitive_le … IH6) // |
---|
998 | | #j #LTj >reverse_append >reverse_reverse cases (IH … LTj) -IH #K #IH % |
---|
999 | [ >length_append @(lt_to_le_to_lt … K) // |
---|
1000 | | >IH @shift_nth_prefix ]]]]] |
---|
1001 | qed. |
---|
1002 | |
---|
1003 | definition assembly_unlabelled_program: |
---|
1004 | assembly_program → option (list Byte × (BitVectorTrie Identifier 16)) ≝ |
---|
1005 | λp. |
---|
1006 | Some … (〈foldr … (λi,l. assembly1 i @ l) [ ] p, Stub …〉). |
---|