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 *)
18 (* Sviluppato da: Ing. Cosimo Oliboni, oliboni@cs.unibo.it *)
19 (* Ultima modifica: 05/08/2009 *)
21 (* ********************************************************************** *)
23 include "freescale_tests/micro_tests_tools.ma".
24 include "freescale/multivm.ma".
25 include "freescale/status_lemmas.ma".
26 include "common/nat_to_num.ma".
28 (* ****************************************** *)
29 (* MICRO TEST DI CORRETTEZZA DELLE ISTRUZIONI *)
30 (* ****************************************** *)
32 (* ********************* *)
33 (* TEOREMA MULT PER RS08 *)
34 (* ********************* *)
36 ndefinition mTest_RS08_mult_source ≝ let m ≝ RS08 in source_to_byte8 m (
38 ZH:ZL=X*Y con [0x0020-0x004F] X ≝ [0x0020] Y ≝ [0x0021] ZH ≝ [0x0022] ZL ≝ [0x0023]
40 (* [0x3800] ZH <- 0 3clk *) (compile m ? CLR (maDIR1 〈x2,x2〉) I) @
41 (* [0x3802] ZL <- 0 3clk *) (compile m ? CLR (maDIR1 〈x2,x3〉) I) @
42 (* [0x3804] (l1) A <- Y 3clk *) (compile m ? LDA (maDIR1 〈x2,x1〉) I) @
43 (* [0x3806] A=0 goto l2 3clk *) (compile m ? BEQ (maIMM1 〈x0,xE〉) I) @
44 (* [0x3808] A <- ZL 3clk *) (compile m ? LDA (maDIR1 〈x2,x3〉) I) @
45 (* [0x380A] Y -- 5clk *) (compile m ? DEC (maDIR1 〈x2,x1〉) I) @
46 (* [0x380C] A += X 3clk *) (compile m ? ADD (maDIR1 〈x2,x0〉) I) @
47 (* [0x380E] C=0 goto l3 3clk *) (compile m ? BCC (maIMM1 〈x0,x2〉) I) @
48 (* [0x3810] ZH ++ 5clk *) (compile m ? INC (maDIR1 〈x2,x2〉) I) @
49 (* [0x3812] (l3) ZL <- A 3clk *) (compile m ? STA (maDIR1 〈x2,x3〉) I) @
50 (* [0x3814] goto l1 3clk *) (compile m ? BRA (maIMM1 〈xE,xE〉) I)
51 (* [0x3816] (l2) si puo' quindi enunciare che
52 - il caso base X * 0 richiede 12 cicli
53 - bisogna aggiungere Y * 26 cicli, Y>0
54 - bisogna aggiungere ZH * 5 cicli, X * Y > 0xFF *)
57 (* creazione del processore+caricamento+impostazione registri *)
58 ndefinition mTest_RS08_mult_status ≝
61 set_z_flag RS08 t (* Z<-true *)
62 (set_pc_reg RS08 t (* PC<-mTest_RS08_prog *)
63 (start_of_mcu_version_RS08
65 (load_from_source_at t (* carica X,Y,ZH,ZL:mTest_RS08_RAM *)
66 (load_from_source_at t (zero_memory t) (* carica source in ROM:mTest_RS08_prog *)
67 mTest_RS08_mult_source mTest_RS08_prog)
68 [ b1 ; b2 ; b3 ; b4 ] mTest_RS08_RAM)
69 (build_memory_type_of_mcu_version (FamilyRS08 MC9RS08KA2) t)
70 (mk_byte8 x0 x0) (mk_byte8 x0 x0) (* non deterministici tutti a 0 *)
71 false false false false false false (* non deterministici tutti a 0 *)
75 (* parametrizzazione dell'enunciato del teorema mult *)
76 (* NB: la memoria e' cambiata e bisogna applicare eq_status *)
77 ndefinition ok_mTest_RS08_mult_full_aux ≝
78 λt:memory_impl.λX,Y:byte8.
80 (match execute RS08 t (TickOK ? (mTest_RS08_mult_status t X Y 〈x0,x0〉 〈x0,x0〉))
81 (nat12 + (nat26 * (nat_of_b8 Y)) + (nat5 * (nat_of_b8 (w16h (mul_b8 X Y)))))
82 (* FIXME: alla ALU azzero C perche' la funzione che ne descrive il valore finale e' MOLTO complessa *)
83 with [ TickERR s _ ⇒ s | TickSUSP s _ ⇒ s | TickOK s ⇒ set_c_flag RS08 t s false ])
84 (set_pc_reg RS08 t (mTest_RS08_mult_status t X 〈x0,x0〉 (w16h (mul_b8 X Y)) (w16l (mul_b8 X Y))) 〈〈x3,x8〉:〈x1,x6〉〉)
85 (* controllo che coincidano X,Y,ZH,ZL *)
86 [ 〈〈x0,x0〉:〈x2,x0〉〉 ; 〈〈x0,x0〉:〈x2,x1〉〉 ; 〈〈x0,x0〉:〈x2,x2〉〉 ; 〈〈x0,x0〉:〈x2,x3〉〉 ] = true.
88 nlemma ok_mTest_RS08_mult_full :
92 ok_mTest_RS08_mult_full_aux t X Y.
96 napply (eq_to_eqanystatus_weak [ 〈〈x0,x0〉:〈x2,x0〉〉 ; 〈〈x0,x0〉:〈x2,x1〉〉 ; 〈〈x0,x0〉:〈x2,x2〉〉 ; 〈〈x0,x0〉:〈x2,x3〉〉 ] RS08 t
97 (match execute RS08 t (TickOK ? (mTest_RS08_mult_status t X Y 〈x0,x0〉 〈x0,x0〉))
98 (nat12 + (nat26 * (nat_of_b8 Y)) + (nat5 * (nat_of_b8 (w16h (mul_b8 X Y)))))
99 with [ TickERR s _ ⇒ s | TickSUSP s _ ⇒ s | TickOK s ⇒ set_c_flag RS08 t s false ])
100 (set_pc_reg RS08 t (mTest_RS08_mult_status t X 〈x0,x0〉 (w16h (mul_b8 X Y)) (w16l (mul_b8 X Y))) 〈〈x3,x8〉:〈x1,x6〉〉));
102 nnormalize in ⊢ (? ? ? %);