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 include "freescale/memory_struct.ma".
29 (* ********************* *)
30 (* MEMORIA E DESCRITTORE *)
31 (* ********************* *)
33 (* (mf_check_update_ranged chk inf sup mode) = setta tipo memoria *)
34 definition mf_check_update_ranged ≝
35 λf:word16 → memory_type.λi.λs.λv.
36 λx.match in_range x i s with
40 (* tutta la memoria non installata *)
41 definition mf_out_of_bound_memory ≝ λ_:word16.MEM_OUT_OF_BOUND.
43 definition mf_chk_get ≝
44 λc:word16 → memory_type.λa:word16.
46 [ MEM_READ_ONLY ⇒ array_8T ? MEM_READ_ONLY MEM_READ_ONLY MEM_READ_ONLY MEM_READ_ONLY MEM_READ_ONLY MEM_READ_ONLY MEM_READ_ONLY MEM_READ_ONLY
47 | MEM_READ_WRITE ⇒ array_8T ? MEM_READ_WRITE MEM_READ_WRITE MEM_READ_WRITE MEM_READ_WRITE MEM_READ_WRITE MEM_READ_WRITE MEM_READ_WRITE MEM_READ_WRITE
48 | MEM_OUT_OF_BOUND ⇒ array_8T ? MEM_OUT_OF_BOUND MEM_OUT_OF_BOUND MEM_OUT_OF_BOUND MEM_OUT_OF_BOUND MEM_OUT_OF_BOUND MEM_OUT_OF_BOUND MEM_OUT_OF_BOUND MEM_OUT_OF_BOUND
51 (* (mf_mem_update mem checked addr val) = scrivi controllando il tipo di memoria *)
52 definition mf_mem_update ≝
53 λf:word16 → byte8.λc:Prod8T memory_type.λa:word16.λv:byte8.
54 match getn_array8T o0 ? c with
55 (* ROM? ok, ma il valore viene perso *)
56 [ MEM_READ_ONLY ⇒ Some ? f
58 | MEM_READ_WRITE ⇒ Some ? (λx.match eq_w16 x a with [ true ⇒ v | false ⇒ f x ])
59 (* NON INSTALLATA? no *)
60 | MEM_OUT_OF_BOUND ⇒ None ? ].
62 (* tutta la memoria a 0 *)
63 definition mf_zero_memory ≝ λ_:word16.〈x0,x0〉.
65 (* (mf_mem_read mem check addr) = leggi controllando il tipo di memoria *)
66 definition mf_mem_read ≝
67 λf:word16 → byte8.λc:word16 → memory_type.λa.
69 [ MEM_READ_ONLY ⇒ Some ? (f a)
70 | MEM_READ_WRITE ⇒ Some ? (f a)
71 | MEM_OUT_OF_BOUND ⇒ None ? ].
73 (* ************************** *)
74 (* CARICAMENTO PROGRAMMA/DATI *)
75 (* ************************** *)
77 (* carica a paratire da addr, scartando source (pescando da old_mem) se si supera 0xFFFF... *)
78 let rec mf_load_from_source_at (old_mem:word16 → byte8) (source:list byte8) (addr:word16) on source ≝
80 (* fine di source: carica da old_mem *)
82 | cons hd tl ⇒ λx:word16.match lt_w16 x addr with
83 (* e' prima di source: carica da old_mem *)
85 | false ⇒ match eq_w16 x addr with
86 (* la locazione corrisponde al punto corrente di source *)
88 (* la locazione e' piu' avanti: ricorsione *)
89 | false ⇒ (mf_load_from_source_at old_mem tl (plus_w16nc addr 〈〈x0,x0〉:〈x0,x1〉〉)) x
94 (* ********************** *)
95 (* TEOREMI/LEMMMI/ASSIOMI *)
96 (* ********************** *)
99 lemma mem_update_mem_update_a_a:
101 mem_update (mem_update s a v1) a v2 b = mem_update s a v2 b.
109 lemma mem_update_mem_update_a_b:
112 mem_update (mem_update s a1 v1) a2 v2 b = mem_update (mem_update s a2 v2) a1 v1 b.
116 apply (bool_elim ? (eqb b a1)); intros;
117 apply (bool_elim ? (eqb b a2)); intros;
120 rewrite < (eqb_true_to_eq ? ? H1);
121 apply eqb_true_to_eq;
127 lemma eq_update_s_a_sa: ∀s,a,b. update s a (s a) b = s b.
130 apply (bool_elim ? (eqb b a) ? ?); simplify; intros;
131 [ rewrite > (eqb_true_to_eq ? ? H);
138 ∀s,s',a,v,b. (a ≠ b → s b = s' b) → update s a v b = update s' a v b.
141 apply (bool_elim ? (eqb b a) ? ?); simplify; intros;
149 lemma not_eq_a_b_to_eq_update_a_b: ∀s,a,b,v. a ≠ b → update s a v b = s b.
152 rewrite > not_eq_to_eqb_false; simplify;