1 (**************************************************************************)
4 (* ||A|| A project by Andrea Asperti *)
6 (* ||I|| Developers: *)
7 (* ||T|| The HELM team. *)
8 (* ||A|| http://helm.cs.unibo.it *)
10 (* \ / This file is distributed under the terms of the *)
11 (* v GNU General Public License Version 2 *)
13 (**************************************************************************)
15 (* ********************************************************************** *)
16 (* Progetto FreeScale *)
19 (* Cosimo Oliboni, oliboni@cs.unibo.it *)
21 (* Questo materiale fa parte della tesi: *)
22 (* "Formalizzazione Interattiva dei Microcontroller a 8bit FreeScale" *)
24 (* data ultima modifica 15/11/2007 *)
25 (* ********************************************************************** *)
27 set "baseuri" "cic:/matita/freescale/tests/".
29 (*include "/media/VIRTUOSO/freescale/micro_tests.ma".*)
30 include "freescale/micro_tests.ma".
33 RAM indirizzabile in modalita' diretta da usare per X,Y,Z
34 A=X*Y (parte low) con [0x0020-0x004F] X ≝ [0x0020] Y ≝ [0x0021] Z ≝ [0x0022]
36 definition test_mult_source_RS08 : list byte8 ≝
37 let m ≝ RS08 in source_to_byte8 m (
38 (* [0x3800] Z <- 0 3clk *) (compile m ? CLR (maDIR1 〈x2,x2〉) I) @
39 (* [0x3802] (l1) A <- Y 3clk *) (compile m ? LDA (maDIR1 〈x2,x1〉) I) @
40 (* [0x3804] A=0 goto l2 3clk *) (compile m ? BEQ (maIMM1 〈x0,xA〉) I) @
41 (* [0x3806] A <- Z 3clk *) (compile m ? LDA (maDIR1 〈x2,x2〉) I) @
42 (* [0x3808] Y -- 5clk *) (compile m ? DEC (maDIR1 〈x2,x1〉) I) @
43 (* [0x380A] A += X 3clk *) (compile m ? ADD (maDIR1 〈x2,x0〉) I) @
44 (* [0x380C] Z <- A 3clk *) (compile m ? STA (maDIR1 〈x2,x2〉) I) @
45 (* [0x380E] goto l1 3clk *) (compile m ? BRA (maIMM1 〈xF,x2〉) I) @
46 (* [0x3810] (l2) A <- Z 3clk *) (compile m ? LDA (maDIR1 〈x2,x2〉) I)
53 definition mult_memory ≝
56 [ true ⇒ nth ? mult_source 〈x0, x0〉 a
64 definition mult_status ≝
66 mk_status 〈x0, x0〉 0 0 false false (mult_memory x y) 0.
68 notation " 'M' \sub (x y)" non associative with precedence 80 for
71 interpretation "mult_memory" 'memory x y =
72 (cic:/matita/freescale/test/mult_memory.con x y).
74 notation " 'M' \sub (x y) \nbsp a" non associative with precedence 80 for
75 @{ 'memory4 $x $y $a }.
77 interpretation "mult_memory4" 'memory4 x y a =
78 (cic:/matita/freescale/test/mult_memory.con x y a).
80 notation " \Sigma \sub (x y)" non associative with precedence 80 for
83 interpretation "mult_status" 'status x y =
84 (cic:/matita/freescale/test/mult_status.con x y).
88 let s ≝ execute (mult_status 〈x0, x0〉 〈x0, x0〉) i in
89 pc s = 20 ∧ mem s 32 = byte_of_nat 0.
97 let i ≝ 14 + 23 * nat_of_byte y in
98 let s ≝ execute (mult_status x y) i in
99 pc s = 20 ∧ mem s 32 = plusbytenc x x.
108 let i ≝ 14 + 23 * nat_of_byte y in
109 let s ≝ execute (mult_status x y) i in
110 pc s = 20 ∧ mem s 32 = x.
114 | change in ⊢ (? ? % ?) with (plusbytenc 〈x0, x0〉 x);
115 rewrite > plusbytenc_O_x;
123 let i ≝ 14 + 23 * nat_of_byte y in
124 let s ≝ execute (mult_status x y) i in
125 pc s = 20 ∧ mem s 32 = plusbytenc x x.
129 | change in ⊢ (? ? % ?) with
130 (plusbytenc (plusbytenc 〈x0, x0〉 x) x);
131 rewrite > plusbytenc_O_x;
136 lemma loop_invariant':
137 ∀x,y:byte.∀j:nat. j ≤ y →
138 execute (mult_status x y) (5 + 23*j)
140 mk_status (byte_of_nat (x * j)) 4 0 (eqbyte 〈x0, x0〉 (byte_of_nat (x*j)))
141 (plusbytec (byte_of_nat (x*pred j)) x)
142 (update (update (update (mult_memory x y) 30 x) 31 (byte_of_nat (y - j))) 32
143 (byte_of_nat (x * j)))
147 [ do 2 (rewrite < times_n_O);
149 [1,2,3,4,7: normalize; reflexivity
150 | rewrite > eq_plusbytec_x0_x0_x_false;
155 normalize in ⊢ (? ? (? (? ? %) ?) ?);
156 change in ⊢ (? ? % ?) with (update (mult_memory x y) 32 〈x0, x0〉 a);
157 simplify in ⊢ (? ? ? %);
158 change in ⊢ (? ? ? (? (? (? ? ? %) ? ?) ? ? ?)) with (mult_memory x y 30);
159 rewrite > byte_of_nat_nat_of_byte;
160 change in ⊢ (? ? ? (? (? ? ? %) ? ? ?)) with (mult_memory x y 31);
163 rewrite > (eq_update_s_a_sa (update (mult_memory x y) 30 (mult_memory x y 30))
165 rewrite > eq_update_s_a_sa;
168 | cut (5 + 23 * S n = 5 + 23 * n + 23);
169 [ rewrite > Hcut; clear Hcut;
170 rewrite > breakpoint;
171 rewrite > H; clear H;
172 [2: apply le_S_S_to_le;
175 | cut (∃z.y-n=S z ∧ z < 255);
176 [ elim Hcut; clear Hcut;
179 (* instruction LDAd *)
180 change in ⊢ (? ? (? ? %) ?) with (3+20);
181 rewrite > breakpoint in ⊢ (? ? % ?);
182 whd in ⊢ (? ? (? % ?) ?);
183 normalize in ⊢ (? ? (? (? ? % ? ? ? ? ?) ?) ?);
184 change in ⊢ (? ? (? (? % ? ? ? ? ? ?) ?) ?)
185 with (byte_of_nat (S a));
186 change in ⊢ (? ? (? (? ? ? ? (? ? %) ? ? ?) ?) ?) with
188 (* instruction BEQ *)
189 change in ⊢ (? ? (? ? %) ?) with (3+17);
190 rewrite > breakpoint in ⊢ (? ? % ?);
191 whd in ⊢ (? ? (? % ?) ?);
192 letin K ≝ (eq_eqbyte_x0_x0_byte_of_nat_S_false ? H3); clearbody K;
193 rewrite > K; clear K;
194 simplify in ⊢ (? ? (? (? ? % ? ? ? ? ?) ?) ?);
195 (* instruction LDAd *)
196 change in ⊢ (? ? (? ? %) ?) with (3+14);
197 rewrite > breakpoint in ⊢ (? ? % ?);
198 whd in ⊢ (? ? (? % ?) ?);
199 change in ⊢ (? ? (? (? % ? ? ? ? ? ?) ?) ?) with (byte_of_nat (x*n));
200 normalize in ⊢ (? ? (? (? ? % ? ? ? ? ?) ?) ?);
201 change in ⊢ (? ? (? (? ? ? ? % ? ? ?) ?) ?) with (eqbyte 〈x0, x0〉 (byte_of_nat (x*n)));
202 (* instruction DECd *)
203 change in ⊢ (? ? (? ? %) ?) with (5+9);
204 rewrite > breakpoint in ⊢ (? ? % ?);
205 whd in ⊢ (? ? (? % ?) ?);
206 change in ⊢ (? ? (? (? ? ? ? (? ? %) ? ? ?) ?) ?) with (bpred (byte_of_nat (S a)));
207 rewrite > (eq_bpred_S_a_a ? H3);
208 normalize in ⊢ (? ? (? (? ? % ? ? ? ? ?) ?) ?);
209 normalize in ⊢ (? ? (? (? ? ? ? ? ? (? ? % ?) ?) ?) ?);
211 [2: rewrite > eq_minus_S_pred;
214 rewrite < Hcut; clear Hcut; clear H3; clear H2; clear a;
215 (* instruction ADDd *)
216 change in ⊢ (? ? (? ? %) ?) with (3+6);
217 rewrite > breakpoint in ⊢ (? ? % ?);
218 whd in ⊢ (? ? (? % ?) ?);
219 change in ⊢ (? ? (? (? % ? ? ? ? ? ?) ?) ?) with
220 (plusbytenc (byte_of_nat (x*n)) x);
221 change in ⊢ (? ? (? (? ? ? ? (? ? %) ? ? ?) ?) ?) with
222 (plusbytenc (byte_of_nat (x*n)) x);
223 normalize in ⊢ (? ? (? (? ? % ? ? ? ? ?) ?) ?);
224 change in ⊢ (? ? (? (? ? ? ? ? % ? ?) ?) ?)
225 with (plusbytec (byte_of_nat (x*n)) x);
226 rewrite > plusbytenc_S;
227 (* instruction STAd *)
228 rewrite > (breakpoint ? 3 3);
229 whd in ⊢ (? ? (? % ?) ?);
230 normalize in ⊢ (? ? (? (? ? % ? ? ? ? ?) ?) ?);
231 (* instruction BRA *)
233 normalize in ⊢ (? ? (? ? % ? ? ? ? ?) ?);
236 [1,2,3,4,7: normalize; reflexivity
237 | change with (plusbytec #(x*n) x = plusbytec #(x*n) x);
240 simplify in ⊢ (? ? ? %);
241 normalize in ⊢ (? ? (? (? ? ? ? ? ? (? ? (? %) ?) ?) ?) ?);
242 change in ⊢ (? ? % ?) with
243 ((mult_memory x y){30↦x}{31↦#(S (y-S n))}{32↦#(x*n)}{31↦#(y-S n)}
244 {〈x2,x0〉↦ #(x*S n)} a);
249 rewrite > not_eq_a_b_to_eq_update_a_b; [2: apply H | ];
250 rewrite > not_eq_a_b_to_eq_update_a_b;
258 [ rewrite < (minus_S_S y n);
259 apply (minus_Sn_m (nat_of_byte y) (S n) H1)
260 | letin K ≝ (lt_nat_of_byte_256 y); clearbody K;
261 letin K' ≝ (lt_minus_m y (S n) ? ?); clearbody K';
262 [ apply (lt_to_le_to_lt O (S n) (nat_of_byte y) ? ?);
271 | rewrite > associative_plus;
272 rewrite < times_n_Sm;
273 rewrite > sym_plus in ⊢ (? ? ? (? ? %));
282 let i ≝ 14 + 23 * y in
283 execute (mult_status x y) i =
284 mk_status (#(x*y)) 20 0
285 (eqbyte 〈x0, x0〉 (#(x*y)))
286 (plusbytec (byte_of_nat (x*pred y)) x)
288 (update (mult_memory x y) 31 〈x0, x0〉)
289 32 (byte_of_nat (x*y)))
292 cut (14 + 23 * y = 5 + 23*y + 9);
293 [2: autobatch paramodulation;
294 | rewrite > Hcut; (* clear Hcut; *)
295 rewrite > (breakpoint (mult_status x y) (5 + 23*y) 9);
296 rewrite > loop_invariant';
298 | rewrite < minus_n_n;
300 [1,2,3,4,5,7: normalize; reflexivity
302 simplify in ⊢ (? ? ? %);
303 change in ⊢ (? ? % ?) with
304 (update (update (update (mult_memory x y) 30 x) 31 (byte_of_nat O)) 32
305 (byte_of_nat (nat_of_byte x*nat_of_byte y)) a);
306 repeat (apply inj_update; intro);
307 apply (eq_update_s_a_sa ? 30)