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: Cosimo Oliboni, oliboni@cs.unibo.it *)
19 (* Cosimo Oliboni, oliboni@cs.unibo.it *)
21 (* ********************************************************************** *)
23 include "freescale/memory_abs.ma".
24 include "freescale/opcode_base.ma".
25 include "freescale/prod.ma".
27 (* *********************************** *)
28 (* STATUS INTERNO DEL PROCESSORE (ALU) *)
29 (* *********************************** *)
32 nrecord alu_HC05: Type ≝
34 (* A: registo accumulatore *)
35 acc_low_reg_HC05 : byte8;
36 (* X: registro indice *)
37 indX_low_reg_HC05 : byte8;
38 (* SP: registo stack pointer *)
40 (* modificatori di SP: per esempio e' definito come 0000000011xxxxxxb *)
41 (* la logica della sua costruzione e' quindi (SP∧mask)∨fix *)
42 (* totalmente racchiusa nella ALU, bastera' fare get(set(SP)) *)
43 sp_mask_HC05 : word16;
45 (* PC: registro program counter *)
47 (* modificatore di PC: per esempio e' definito come 00xxxxxxxxxxxxxxb *)
48 (* la logica della sua costruzione e' quindi (PC∧mask) *)
49 (* totalmente racchiusa nella ALU, bastera' fare get(set(PC)) *)
50 pc_mask_HC05 : word16;
52 (* H: flag semi-carry (somma nibble basso) *)
54 (* I: flag mascheramento degli interrupt mascherabili: 1=mascherati *)
56 (* N: flag segno/negativita' *)
63 (* IRQ: flag che simula il pin esterno IRQ *)
67 notation "{hvbox('A_Reg' ≝ acclow ; break 'X_Reg' ≝ indxlow ; break 'Sp_Reg' ≝ sp ; break 'Sp_Mask' ≝ spm ; break 'Sp_Fix' ≝ spf ; break 'Pc_Reg' ≝ pc ; break 'Pc_Mask' ≝ pcm ; break 'H_Flag' ≝ hfl ; break 'I_Flag' ≝ ifl ; break 'N_Flag' ≝ nfl ; break 'Z_Flag' ≝ zfl ; break 'C_Flag' ≝ cfl ; break 'IRQ_Flag' ≝ irqfl)}"
68 non associative with precedence 80 for
69 @{ 'mk_alu_HC05 $acclow $indxlow $sp $spm $spf $pc $pcm $hfl $ifl $nfl $zfl $cfl $irqfl }.
70 interpretation "mk_alu_HC05" 'mk_alu_HC05 acclow indxlow sp spm spf pc pcm hfl ifl nfl zfl cfl irqfl =
71 (mk_alu_HC05 acclow indxlow sp spm spf pc pcm hfl ifl nfl zfl cfl irqfl).
73 (* ALU dell'HC08/HCS08 *)
74 nrecord alu_HC08: Type ≝
76 (* A: registo accumulatore *)
77 acc_low_reg_HC08 : byte8;
78 (* X: registro indice parte bassa *)
79 indX_low_reg_HC08 : byte8;
80 (* H: registro indice parte alta *)
81 indX_high_reg_HC08 : byte8;
82 (* SP: registo stack pointer *)
84 (* PC: registro program counter *)
87 (* V: flag overflow *)
89 (* H: flag semi-carry (somma nibble basso) *)
91 (* I: flag mascheramento degli interrupt mascherabili: 1=mascherati *)
93 (* N: flag segno/negativita' *)
100 (* IRQ: flag che simula il pin esterno IRQ *)
104 notation "{hvbox('A_Reg' ≝ acclow ; break 'X_Reg' ≝ indxlow ; break 'H_Reg' ≝ indxhigh ; break 'Sp_Reg' ≝ sp ; break 'Pc_Reg' ≝ pc ; break 'V_Flag' ≝ vfl ; break 'H_Flag' ≝ hfl ; break 'I_Flag' ≝ ifl ; break 'N_Flag' ≝ nfl ; break 'Z_Flag' ≝ zfl ; break 'C_Flag' ≝ cfl ; break 'IRQ_Flag' ≝ irqfl)}"
105 non associative with precedence 80 for
106 @{ 'mk_alu_HC08 $acclow $indxlow $indxhigh $sp $pc $vfl $hfl $ifl $nfl $zfl $cfl $irqfl }.
107 interpretation "mk_alu_HC08" 'mk_alu_HC08 acclow indxlow indxhigh sp pc vfl hfl ifl nfl zfl cfl irqfl =
108 (mk_alu_HC08 acclow indxlow indxhigh sp pc vfl hfl ifl nfl zfl cfl irqfl).
111 nrecord alu_RS08: Type ≝
113 (* A: registo accumulatore *)
114 acc_low_reg_RS08 : byte8;
115 (* PC: registro program counter *)
116 pc_reg_RS08 : word16;
117 (* modificatore di PC: per esempio e' definito come 00xxxxxxxxxxxxxxb *)
118 (* la logica della sua costruzione e' quindi (PC∧mask) *)
119 (* totalmente racchiusa nella ALU, bastera' fare get(set(PC)) *)
120 pc_mask_RS08 : word16;
121 (* SPC: registro shadow program counter *)
122 (* NB: il suo modificatore e' lo stesso di PC *)
123 spc_reg_RS08 : word16;
125 (* X: registro indice parte bassa *)
126 (* NB: in realta' e' mappato in memoria e non risiede nella ALU *)
127 (* la lettura/scrittura avviene tramite la locazione [0x000F] *)
128 (* la funzione memory_filter_read/write si occupera' di intercettare *)
129 (* e deviare sul registro le letture/scritture (modulo load_write) *)
131 (* PS: registro selezione di pagina *)
132 (* serve a indirizzare la finestra RAM di 64b [0x00C0-0x00FF] *)
133 (* su tutta la memoria installata [0x0000-0x3FFF]: [00pp pppp ppxx xxxx] *)
134 (* NB: in realta' e' mappato in memoria e non risiede nella ALU *)
135 (* la lettura/scrittura avviene tramite la locazione [0x001F] *)
136 (* la funzione memory_filter_read/write si occupera' di intercettare *)
137 (* e deviare sul registro le letture/scritture (modulo load_write) *)
146 notation "{hvbox('A_Reg' ≝ acclow ; break 'Pc_Reg' ≝ pc ; break 'Pc_Mask' ≝ pcm ; break 'Spc_Reg' ≝ spc ; break 'X_Map' ≝ xm ; break 'Ps_Map' ≝ psm ; break 'Z_Flag' ≝ zfl ; break 'C_Flag' ≝ cfl)}"
147 non associative with precedence 80 for
148 @{ 'mk_alu_RS08 $acclow $pc $pcm $spc $xm $psm $zfl $cfl }.
149 interpretation "mk_alu_RS08" 'mk_alu_RS08 acclow pc pcm spc xm psm zfl cfl =
150 (mk_alu_RS08 acclow pc pcm spc xm psm zfl cfl).
152 (* tipo processore dipendente dalla mcu, varia solo la ALU *)
153 nrecord any_status (mcu:mcu_type) (t:memory_impl): Type ≝
156 [ HC05 ⇒ alu_HC05 | HC08 ⇒ alu_HC08 | HCS08 ⇒ alu_HC08 | RS08 ⇒ alu_RS08 ];
158 (* descritore della memoria *)
159 mem_desc : aux_mem_type t;
160 (* descrittore del tipo di memoria installata *)
161 chk_desc : aux_chk_type t;
162 (* descrittore del click = stato di avanzamento dell'esecuzione+cur_pc conseguente a fetch *)
163 (* 1) None = istruzione eseguita, attesa del fetch *)
164 (* 2) Some cur_clk,pseudo,mode,clks,cur_pc = fetch eseguito, countup a esecuzione *)
165 clk_desc : option (Prod5T byte8 (any_opcode mcu) (instr_mode) byte8 word16)
169 (* evitare di mostrare la memoria/descrittore che impalla il visualizzatore *)
170 notation > "{hvbox('Alu' ≝ alu ; break 'Clk' ≝ clk)}" non associative with precedence 80
171 for @{ 'mk_any_status $alu $mem $chk $clk }.
172 interpretation "mk_any_status" 'mk_any_status alu mem chk clk =
173 (mk_any_status alu mem chk clk).
175 (* **************** *)
176 (* GETTER SPECIFICI *)
177 (* **************** *)
179 (* funzione ausiliaria per il tipaggio dei getter *)
180 ndefinition aux_get_typing ≝ λx:Type.λm:mcu_type.match m with
181 [ HC05 ⇒ alu_HC05 | HC08 ⇒ alu_HC08 | HCS08 ⇒ alu_HC08 | RS08 ⇒ alu_RS08 ] → x.
185 (* getter di A, esiste sempre *)
186 ndefinition get_acc_8_low_reg ≝
187 λm:mcu_type.λt:memory_impl.λs:any_status m t.
189 return aux_get_typing byte8 with
190 [ HC05 ⇒ acc_low_reg_HC05
191 | HC08 ⇒ acc_low_reg_HC08
192 | HCS08 ⇒ acc_low_reg_HC08
193 | RS08 ⇒ acc_low_reg_RS08 ]
196 (* getter di X, non esiste sempre *)
197 ndefinition get_indX_8_low_reg ≝
198 λm:mcu_type.λt:memory_impl.λs:any_status m t.
200 return aux_get_typing (option byte8) with
201 [ HC05 ⇒ λalu.Some ? (indX_low_reg_HC05 alu)
202 | HC08 ⇒ λalu.Some ? (indX_low_reg_HC08 alu)
203 | HCS08 ⇒ λalu.Some ? (indX_low_reg_HC08 alu)
204 | RS08 ⇒ λalu.None ? ]
207 (* getter di H, non esiste sempre *)
208 ndefinition get_indX_8_high_reg ≝
209 λm:mcu_type.λt:memory_impl.λs:any_status m t.
211 return aux_get_typing (option byte8) with
213 | HC08 ⇒ λalu.Some ? (indX_high_reg_HC08 alu)
214 | HCS08 ⇒ λalu.Some ? (indX_high_reg_HC08 alu)
215 | RS08 ⇒ λalu.None ? ]
218 (* getter di H:X, non esiste sempre *)
219 ndefinition get_indX_16_reg ≝
220 λm:mcu_type.λt:memory_impl.λs:any_status m t.
222 return aux_get_typing (option word16) with
224 | HC08 ⇒ λalu.Some ? (mk_word16 (indX_high_reg_HC08 alu) (indX_low_reg_HC08 alu))
225 | HCS08 ⇒ λalu.Some ? (mk_word16 (indX_high_reg_HC08 alu) (indX_low_reg_HC08 alu))
226 | RS08 ⇒ λalu.None ? ]
229 (* getter di SP, non esiste sempre *)
230 ndefinition get_sp_reg ≝
231 λm:mcu_type.λt:memory_impl.λs:any_status m t.
233 return aux_get_typing (option word16) with
234 [ HC05 ⇒ λalu.Some ? (sp_reg_HC05 alu)
235 | HC08 ⇒ λalu.Some ? (sp_reg_HC08 alu)
236 | HCS08 ⇒ λalu.Some ? (sp_reg_HC08 alu)
237 | RS08 ⇒ λalu.None ? ]
240 (* getter di PC, esiste sempre *)
241 ndefinition get_pc_reg ≝
242 λm:mcu_type.λt:memory_impl.λs:any_status m t.
244 return aux_get_typing word16 with
247 | HCS08 ⇒ pc_reg_HC08
248 | RS08 ⇒ pc_reg_RS08 ]
251 (* getter di SPC, non esiste sempre *)
252 ndefinition get_spc_reg ≝
253 λm:mcu_type.λt:memory_impl.λs:any_status m t.
255 return aux_get_typing (option word16) with
258 | HCS08 ⇒ λalu.None ?
259 | RS08 ⇒ λalu.Some ? (spc_reg_RS08 alu) ]
262 (* REGISTRI MEMORY MAPPED *)
264 (* getter di memory mapped X, non esiste sempre *)
265 ndefinition get_x_map ≝
266 λm:mcu_type.λt:memory_impl.λs:any_status m t.
268 return aux_get_typing (option byte8) with
271 | HCS08 ⇒ λalu.None ?
272 | RS08 ⇒ λalu.Some ? (x_map_RS08 alu) ]
275 (* getter di memory mapped PS, non esiste sempre *)
276 ndefinition get_ps_map ≝
277 λm:mcu_type.λt:memory_impl.λs:any_status m t.
279 return aux_get_typing (option byte8) with
282 | HCS08 ⇒ λalu.None ?
283 | RS08 ⇒ λalu.Some ? (ps_map_RS08 alu) ]
288 (* getter di V, non esiste sempre *)
289 ndefinition get_v_flag ≝
290 λm:mcu_type.λt:memory_impl.λs:any_status m t.
292 return aux_get_typing (option bool) with
294 | HC08 ⇒ λalu.Some ? (v_flag_HC08 alu)
295 | HCS08 ⇒ λalu.Some ? (v_flag_HC08 alu)
296 | RS08 ⇒ λalu.None ? ]
299 (* getter di H, non esiste sempre *)
300 ndefinition get_h_flag ≝
301 λm:mcu_type.λt:memory_impl.λs:any_status m t.
303 return aux_get_typing (option bool) with
304 [ HC05 ⇒ λalu.Some ? (h_flag_HC05 alu)
305 | HC08 ⇒ λalu.Some ? (h_flag_HC08 alu)
306 | HCS08 ⇒ λalu.Some ? (h_flag_HC08 alu)
307 | RS08 ⇒ λalu.None ? ]
310 (* getter di I, non esiste sempre *)
311 ndefinition get_i_flag ≝
312 λm:mcu_type.λt:memory_impl.λs:any_status m t.
314 return aux_get_typing (option bool) with
315 [ HC05 ⇒ λalu.Some ? (i_flag_HC05 alu)
316 | HC08 ⇒ λalu.Some ? (i_flag_HC08 alu)
317 | HCS08 ⇒ λalu.Some ? (i_flag_HC08 alu)
318 | RS08 ⇒ λalu.None ? ]
321 (* getter di N, non esiste sempre *)
322 ndefinition get_n_flag ≝
323 λm:mcu_type.λt:memory_impl.λs:any_status m t.
325 return aux_get_typing (option bool) with
326 [ HC05 ⇒ λalu.Some ? (n_flag_HC05 alu)
327 | HC08 ⇒ λalu.Some ? (n_flag_HC08 alu)
328 | HCS08 ⇒ λalu.Some ? (n_flag_HC08 alu)
329 | RS08 ⇒ λalu.None ? ]
332 (* getter di Z, esiste sempre *)
333 ndefinition get_z_flag ≝
334 λm:mcu_type.λt:memory_impl.λs:any_status m t.
336 return aux_get_typing bool with
339 | HCS08 ⇒ z_flag_HC08
340 | RS08 ⇒ z_flag_RS08 ]
343 (* getter di C, esiste sempre *)
344 ndefinition get_c_flag ≝
345 λm:mcu_type.λt:memory_impl.λs:any_status m t.
347 return aux_get_typing bool with
350 | HCS08 ⇒ c_flag_HC08
351 | RS08 ⇒ c_flag_RS08 ]
354 (* getter di IRQ, non esiste sempre *)
355 ndefinition get_irq_flag ≝
356 λm:mcu_type.λt:memory_impl.λs:any_status m t.
358 return aux_get_typing (option bool) with
359 [ HC05 ⇒ λalu.Some ? (irq_flag_HC05 alu)
360 | HC08 ⇒ λalu.Some ? (irq_flag_HC08 alu)
361 | HCS08 ⇒ λalu.Some ? (irq_flag_HC08 alu)
362 | RS08 ⇒ λalu.None ? ]
365 (* DESCRITTORI ESTERNI ALLA ALU *)
367 (* getter della ALU, esiste sempre *)
368 ndefinition get_alu ≝ λm:mcu_type.λt:memory_impl.λs:any_status m t.alu m t s.
370 (* getter della memoria, esiste sempre *)
371 ndefinition get_mem_desc ≝ λm:mcu_type.λt:memory_impl.λs:any_status m t.mem_desc m t s.
373 (* getter del descrittore, esiste sempre *)
374 ndefinition get_chk_desc ≝ λm:mcu_type.λt:memory_impl.λs:any_status m t.chk_desc m t s.
376 (* getter del clik, esiste sempre *)
377 ndefinition get_clk_desc ≝ λm:mcu_type.λt:memory_impl.λs:any_status m t.clk_desc m t s.
379 (* ***************************** *)
380 (* SETTER SPECIFICI FORTI/DEBOLI *)
381 (* ***************************** *)
383 (* funzione ausiliaria per il tipaggio dei setter forti *)
384 ndefinition aux_set_typing ≝ λx:Type.λm:mcu_type.
385 match m with [ HC05 ⇒ alu_HC05 | HC08 ⇒ alu_HC08 | HCS08 ⇒ alu_HC08 | RS08 ⇒ alu_RS08 ]
387 match m with [ HC05 ⇒ alu_HC05 | HC08 ⇒ alu_HC08 | HCS08 ⇒ alu_HC08 | RS08 ⇒ alu_RS08 ].
389 (* funzione ausiliaria per il tipaggio dei setter deboli *)
390 ndefinition aux_set_typing_opt ≝ λx:Type.λm:mcu_type.option
391 (match m with [ HC05 ⇒ alu_HC05 | HC08 ⇒ alu_HC08 | HCS08 ⇒ alu_HC08 | RS08 ⇒ alu_RS08 ]
393 match m with [ HC05 ⇒ alu_HC05 | HC08 ⇒ alu_HC08 | HCS08 ⇒ alu_HC08 | RS08 ⇒ alu_RS08 ]).
395 (* DESCRITTORI ESTERNI ALLA ALU *)
397 (* setter forte della ALU *)
398 ndefinition set_alu ≝
399 λm:mcu_type.λt:memory_impl.λs:any_status m t.λalu'.
400 mk_any_status m t alu' (get_mem_desc m t s) (get_chk_desc m t s) (get_clk_desc m t s).
402 (* setter forte della memoria *)
403 ndefinition set_mem_desc ≝
404 λm:mcu_type.λt:memory_impl.λs:any_status m t.λmem':aux_mem_type t.
405 mk_any_status m t (get_alu m t s) mem' (get_chk_desc m t s) (get_clk_desc m t s).
407 (* setter forte del descrittore *)
408 ndefinition set_chk_desc ≝
409 λm:mcu_type.λt:memory_impl.λs:any_status m t.λchk':aux_chk_type t.
410 mk_any_status m t (get_alu m t s) (get_mem_desc m t s) chk' (get_clk_desc m t s).
412 (* setter forte del clik *)
413 ndefinition set_clk_desc ≝
414 λm:mcu_type.λt:memory_impl.λs:any_status m t.
415 λclk':option (Prod5T byte8 (any_opcode m) (instr_mode) byte8 word16).
416 mk_any_status m t (get_alu m t s) (get_mem_desc m t s) (get_chk_desc m t s) clk'.
420 (* setter specifico HC05 di A *)
421 ndefinition set_acc_8_low_reg_HC05 ≝
425 (indX_low_reg_HC05 alu)
438 (* setter specifico HC08/HCS08 di A *)
439 ndefinition set_acc_8_low_reg_HC08 ≝
443 (indX_low_reg_HC08 alu)
444 (indX_high_reg_HC08 alu)
455 (* setter specifico RS08 di A *)
456 ndefinition set_acc_8_low_reg_RS08 ≝
468 (* setter forte di A *)
469 ndefinition set_acc_8_low_reg ≝
470 λm:mcu_type.λt:memory_impl.λs:any_status m t.λacclow':byte8.
472 (match m return aux_set_typing byte8 with
473 [ HC05 ⇒ set_acc_8_low_reg_HC05
474 | HC08 ⇒ set_acc_8_low_reg_HC08
475 | HCS08 ⇒ set_acc_8_low_reg_HC08
476 | RS08 ⇒ set_acc_8_low_reg_RS08
477 ] (alu m t s) acclow').
481 (* setter specifico HC05 di X *)
482 ndefinition set_indX_8_low_reg_HC05 ≝
483 λalu.λindxlow':byte8.
485 (acc_low_reg_HC05 alu)
499 (* setter specifico HC08/HCS08 di X *)
500 ndefinition set_indX_8_low_reg_HC08 ≝
501 λalu.λindxlow':byte8.
503 (acc_low_reg_HC08 alu)
505 (indX_high_reg_HC08 alu)
516 (* setter forte di X *)
517 ndefinition set_indX_8_low_reg ≝
518 λm:mcu_type.λt:memory_impl.λs:any_status m t.λindxlow':byte8.
519 opt_map ?? (match m return aux_set_typing_opt byte8 with
520 [ HC05 ⇒ Some ? set_indX_8_low_reg_HC05
521 | HC08 ⇒ Some ? set_indX_8_low_reg_HC08
522 | HCS08 ⇒ Some ? set_indX_8_low_reg_HC08
524 (λf.Some ? (set_alu m t s (f (alu m t s) indxlow'))).
526 (* setter debole di X *)
527 ndefinition setweak_indX_8_low_reg ≝
528 λm:mcu_type.λt:memory_impl.λs:any_status m t.λindxlow':byte8.
529 match set_indX_8_low_reg m t s indxlow' with
530 [ None ⇒ s | Some s' ⇒ s' ].
534 (* setter specifico HC08/HCS08 di H *)
535 ndefinition set_indX_8_high_reg_HC08 ≝
536 λalu.λindxhigh':byte8.
538 (acc_low_reg_HC08 alu)
539 (indX_low_reg_HC08 alu)
551 (* setter forte di H *)
552 ndefinition set_indX_8_high_reg ≝
553 λm:mcu_type.λt:memory_impl.λs:any_status m t.λindxhigh':byte8.
554 opt_map ?? (match m return aux_set_typing_opt byte8 with
556 | HC08 ⇒ Some ? set_indX_8_high_reg_HC08
557 | HCS08 ⇒ Some ? set_indX_8_high_reg_HC08
559 (λf.Some ? (set_alu m t s (f (alu m t s) indxhigh'))).
561 (* setter debole di H *)
562 ndefinition setweak_indX_8_high_reg ≝
563 λm:mcu_type.λt:memory_impl.λs:any_status m t.λindxhigh':byte8.
564 match set_indX_8_high_reg m t s indxhigh' with
565 [ None ⇒ s | Some s' ⇒ s' ].
569 (* setter specifico HC08/HCS08 di H:X *)
570 ndefinition set_indX_16_reg_HC08 ≝
573 (acc_low_reg_HC08 alu)
586 (* setter forte di H:X *)
587 ndefinition set_indX_16_reg ≝
588 λm:mcu_type.λt:memory_impl.λs:any_status m t.λindx16:word16.
589 opt_map ?? (match m return aux_set_typing_opt word16 with
591 | HC08 ⇒ Some ? set_indX_16_reg_HC08
592 | HCS08 ⇒ Some ? set_indX_16_reg_HC08
594 (λf.Some ? (set_alu m t s (f (alu m t s) indx16))).
596 (* setter debole di H:X *)
597 ndefinition setweak_indX_16_reg ≝
598 λm:mcu_type.λt:memory_impl.λs:any_status m t.λindx16:word16.
599 match set_indX_16_reg m t s indx16 with
600 [ None ⇒ s | Some s' ⇒ s' ].
604 (* setter specifico HC05 di SP, effettua (SP∧mask)∨fix *)
605 ndefinition set_sp_reg_HC05 ≝
608 (acc_low_reg_HC05 alu)
609 (indX_low_reg_HC05 alu)
610 (or_w16 (and_w16 sp' (sp_mask_HC05 alu)) (sp_fix_HC05 alu))
622 (* setter specifico HC08/HCS08 di SP *)
623 ndefinition set_sp_reg_HC08 ≝
626 (acc_low_reg_HC08 alu)
627 (indX_low_reg_HC08 alu)
628 (indX_high_reg_HC08 alu)
639 (* setter forte di SP *)
640 ndefinition set_sp_reg ≝
641 λm:mcu_type.λt:memory_impl.λs:any_status m t.λsp':word16.
642 opt_map ?? (match m return aux_set_typing_opt word16 with
643 [ HC05 ⇒ Some ? set_sp_reg_HC05
644 | HC08 ⇒ Some ? set_sp_reg_HC08
645 | HCS08 ⇒ Some ? set_sp_reg_HC08
647 (λf.Some ? (set_alu m t s (f (alu m t s) sp'))).
649 (* setter debole di SP *)
650 ndefinition setweak_sp_reg ≝
651 λm:mcu_type.λt:memory_impl.λs:any_status m t.λsp':word16.
652 match set_sp_reg m t s sp' with
653 [ None ⇒ s | Some s' ⇒ s' ].
657 (* setter specifico HC05 di PC, effettua PC∧mask *)
658 ndefinition set_pc_reg_HC05 ≝
661 (acc_low_reg_HC05 alu)
662 (indX_low_reg_HC05 alu)
666 (and_w16 pc' (pc_mask_HC05 alu))
675 (* setter specifico HC08/HCS08 di PC *)
676 ndefinition set_pc_reg_HC08 ≝
679 (acc_low_reg_HC08 alu)
680 (indX_low_reg_HC08 alu)
681 (indX_high_reg_HC08 alu)
692 (* setter specifico RS08 di PC, effettua PC∧mask *)
693 ndefinition set_pc_reg_RS08 ≝
696 (acc_low_reg_RS08 alu)
697 (and_w16 pc' (pc_mask_RS08 alu))
705 (* setter forte di PC *)
706 ndefinition set_pc_reg ≝
707 λm:mcu_type.λt:memory_impl.λs:any_status m t.λpc':word16.
709 (match m return aux_set_typing word16 with
710 [ HC05 ⇒ set_pc_reg_HC05
711 | HC08 ⇒ set_pc_reg_HC08
712 | HCS08 ⇒ set_pc_reg_HC08
713 | RS08 ⇒ set_pc_reg_RS08
718 (* setter specifico RS08 di SPC, effettua SPC∧mask *)
719 ndefinition set_spc_reg_RS08 ≝
722 (acc_low_reg_RS08 alu)
725 (and_w16 spc' (pc_mask_RS08 alu))
731 (* setter forte di SPC *)
732 ndefinition set_spc_reg ≝
733 λm:mcu_type.λt:memory_impl.λs:any_status m t.λspc':word16.
734 opt_map ?? (match m return aux_set_typing_opt word16 with
738 | RS08 ⇒ Some ? set_spc_reg_RS08 ])
739 (λf.Some ? (set_alu m t s (f (alu m t s) spc'))).
741 (* setter debole di SPC *)
742 ndefinition setweak_spc_reg ≝
743 λm:mcu_type.λt:memory_impl.λs:any_status m t.λspc':word16.
744 match set_spc_reg m t s spc' with
745 [ None ⇒ s | Some s' ⇒ s' ].
747 (* REGISTRO MEMORY MAPPED X *)
749 (* setter specifico RS08 di memory mapped X *)
750 ndefinition set_x_map_RS08 ≝
753 (acc_low_reg_RS08 alu)
762 (* setter forte di memory mapped X *)
763 ndefinition set_x_map ≝
764 λm:mcu_type.λt:memory_impl.λs:any_status m t.λxm':byte8.
765 opt_map ?? (match m return aux_set_typing_opt byte8 with
769 | RS08 ⇒ Some ? set_x_map_RS08 ])
770 (λf.Some ? (set_alu m t s (f (alu m t s) xm'))).
772 (* setter debole di memory mapped X *)
773 ndefinition setweak_x_map ≝
774 λm:mcu_type.λt:memory_impl.λs:any_status m t.λxm':byte8.
775 match set_x_map m t s xm' with
776 [ None ⇒ s | Some s' ⇒ s' ].
778 (* REGISTRO MEMORY MAPPED PS *)
780 (* setter specifico RS08 di memory mapped PS *)
781 ndefinition set_ps_map_RS08 ≝
784 (acc_low_reg_RS08 alu)
793 (* setter forte di memory mapped PS *)
794 ndefinition set_ps_map ≝
795 λm:mcu_type.λt:memory_impl.λs:any_status m t.λpsm':byte8.
796 opt_map ?? (match m return aux_set_typing_opt byte8 with
800 | RS08 ⇒ Some ? set_ps_map_RS08 ])
801 (λf.Some ? (set_alu m t s (f (alu m t s) psm'))).
803 (* setter debole di memory mapped PS *)
804 ndefinition setweak_ps_map ≝
805 λm:mcu_type.λt:memory_impl.λs:any_status m t.λpsm':byte8.
806 match set_ps_map m t s psm' with
807 [ None ⇒ s | Some s' ⇒ s' ].
811 (* setter specifico HC08/HCS08 di V *)
812 ndefinition set_v_flag_HC08 ≝
815 (acc_low_reg_HC08 alu)
816 (indX_low_reg_HC08 alu)
817 (indX_high_reg_HC08 alu)
828 (* setter forte di V *)
829 ndefinition set_v_flag ≝
830 λm:mcu_type.λt:memory_impl.λs:any_status m t.λvfl':bool.
831 opt_map ?? (match m return aux_set_typing_opt bool with
833 | HC08 ⇒ Some ? set_v_flag_HC08
834 | HCS08 ⇒ Some ? set_v_flag_HC08
836 (λf.Some ? (set_alu m t s (f (alu m t s) vfl'))).
838 (* setter debole di V *)
839 ndefinition setweak_v_flag ≝
840 λm:mcu_type.λt:memory_impl.λs:any_status m t.λvfl':bool.
841 match set_v_flag m t s vfl' with
842 [ None ⇒ s | Some s' ⇒ s' ].
846 (* setter specifico HC05 di H *)
847 ndefinition set_h_flag_HC05 ≝
850 (acc_low_reg_HC05 alu)
851 (indX_low_reg_HC05 alu)
864 (* setter specifico HC08/HCS08 di H *)
865 ndefinition set_h_flag_HC08 ≝
868 (acc_low_reg_HC08 alu)
869 (indX_low_reg_HC08 alu)
870 (indX_high_reg_HC08 alu)
881 (* setter forte di H *)
882 ndefinition set_h_flag ≝
883 λm:mcu_type.λt:memory_impl.λs:any_status m t.λhfl':bool.
884 opt_map ?? (match m return aux_set_typing_opt bool with
885 [ HC05 ⇒ Some ? set_h_flag_HC05
886 | HC08 ⇒ Some ? set_h_flag_HC08
887 | HCS08 ⇒ Some ? set_h_flag_HC08
889 (λf.Some ? (set_alu m t s (f (alu m t s) hfl'))).
891 (* setter debole di H *)
892 ndefinition setweak_h_flag ≝
893 λm:mcu_type.λt:memory_impl.λs:any_status m t.λhfl':bool.
894 match set_h_flag m t s hfl' with
895 [ None ⇒ s | Some s' ⇒ s' ].
899 (* setter specifico HC05 di I *)
900 ndefinition set_i_flag_HC05 ≝
903 (acc_low_reg_HC05 alu)
904 (indX_low_reg_HC05 alu)
917 (* setter specifico HC08/HCS08 di I *)
918 ndefinition set_i_flag_HC08 ≝
921 (acc_low_reg_HC08 alu)
922 (indX_low_reg_HC08 alu)
923 (indX_high_reg_HC08 alu)
934 (* setter forte di I *)
935 ndefinition set_i_flag ≝
936 λm:mcu_type.λt:memory_impl.λs:any_status m t.λifl':bool.
937 opt_map ?? (match m return aux_set_typing_opt bool with
938 [ HC05 ⇒ Some ? set_i_flag_HC05
939 | HC08 ⇒ Some ? set_i_flag_HC08
940 | HCS08 ⇒ Some ? set_i_flag_HC08
942 (λf.Some ? (set_alu m t s (f (alu m t s) ifl'))).
944 (* setter debole di I *)
945 ndefinition setweak_i_flag ≝
946 λm:mcu_type.λt:memory_impl.λs:any_status m t.λifl':bool.
947 match set_i_flag m t s ifl' with
948 [ None ⇒ s | Some s' ⇒ s' ].
952 (* setter specifico HC05 di N *)
953 ndefinition set_n_flag_HC05 ≝
956 (acc_low_reg_HC05 alu)
957 (indX_low_reg_HC05 alu)
970 (* setter specifico HC08/HCS08 di N *)
971 ndefinition set_n_flag_HC08 ≝
974 (acc_low_reg_HC08 alu)
975 (indX_low_reg_HC08 alu)
976 (indX_high_reg_HC08 alu)
987 (* setter forte di N *)
988 ndefinition set_n_flag ≝
989 λm:mcu_type.λt:memory_impl.λs:any_status m t.λnfl':bool.
990 opt_map ?? (match m return aux_set_typing_opt bool with
991 [ HC05 ⇒ Some ? set_n_flag_HC05
992 | HC08 ⇒ Some ? set_n_flag_HC08
993 | HCS08 ⇒ Some ? set_n_flag_HC08
995 (λf.Some ? (set_alu m t s (f (alu m t s) nfl'))).
997 (* setter debole di N *)
998 ndefinition setweak_n_flag ≝
999 λm:mcu_type.λt:memory_impl.λs:any_status m t.λnfl':bool.
1000 match set_n_flag m t s nfl' with
1001 [ None ⇒ s | Some s' ⇒ s' ].
1005 (* setter specifico HC05 di Z *)
1006 ndefinition set_z_flag_HC05 ≝
1009 (acc_low_reg_HC05 alu)
1010 (indX_low_reg_HC05 alu)
1021 (irq_flag_HC05 alu).
1023 (* setter specifico HC08/HCS08 di Z *)
1024 ndefinition set_z_flag_HC08 ≝
1027 (acc_low_reg_HC08 alu)
1028 (indX_low_reg_HC08 alu)
1029 (indX_high_reg_HC08 alu)
1038 (irq_flag_HC08 alu).
1040 (* setter sprcifico RS08 di Z *)
1041 ndefinition set_z_flag_RS08 ≝
1044 (acc_low_reg_RS08 alu)
1053 (* setter forte di Z *)
1054 ndefinition set_z_flag ≝
1055 λm:mcu_type.λt:memory_impl.λs:any_status m t.λzfl':bool.
1057 (match m return aux_set_typing bool with
1058 [ HC05 ⇒ set_z_flag_HC05
1059 | HC08 ⇒ set_z_flag_HC08
1060 | HCS08 ⇒ set_z_flag_HC08
1061 | RS08 ⇒ set_z_flag_RS08
1062 ] (alu m t s) zfl').
1066 (* setter specifico HC05 di C *)
1067 ndefinition set_c_flag_HC05 ≝
1070 (acc_low_reg_HC05 alu)
1071 (indX_low_reg_HC05 alu)
1082 (irq_flag_HC05 alu).
1084 (* setter specifico HC08/HCS08 di C *)
1085 ndefinition set_c_flag_HC08 ≝
1088 (acc_low_reg_HC08 alu)
1089 (indX_low_reg_HC08 alu)
1090 (indX_high_reg_HC08 alu)
1099 (irq_flag_HC08 alu).
1101 (* setter specifico RS08 di C *)
1102 ndefinition set_c_flag_RS08 ≝
1105 (acc_low_reg_RS08 alu)
1114 (* setter forte di C *)
1115 ndefinition set_c_flag ≝
1116 λm:mcu_type.λt:memory_impl.λs:any_status m t.λcfl':bool.
1118 (match m return aux_set_typing bool with
1119 [ HC05 ⇒ set_c_flag_HC05
1120 | HC08 ⇒ set_c_flag_HC08
1121 | HCS08 ⇒ set_c_flag_HC08
1122 | RS08 ⇒ set_c_flag_RS08
1123 ] (alu m t s) cfl').
1127 (* setter specifico HC05 di IRQ *)
1128 ndefinition set_irq_flag_HC05 ≝
1131 (acc_low_reg_HC05 alu)
1132 (indX_low_reg_HC05 alu)
1145 (* setter specifico HC08/HCS08 di IRQ *)
1146 ndefinition set_irq_flag_HC08 ≝
1149 (acc_low_reg_HC08 alu)
1150 (indX_low_reg_HC08 alu)
1151 (indX_high_reg_HC08 alu)
1162 (* setter forte di IRQ *)
1163 ndefinition set_irq_flag ≝
1164 λm:mcu_type.λt:memory_impl.λs:any_status m t.λirqfl':bool.
1165 opt_map ?? (match m return aux_set_typing_opt bool with
1166 [ HC05 ⇒ Some ? set_irq_flag_HC05
1167 | HC08 ⇒ Some ? set_irq_flag_HC08
1168 | HCS08 ⇒ Some ? set_irq_flag_HC08
1170 (λf.Some ? (set_alu m t s (f (alu m t s) irqfl'))).
1172 (* setter debole di IRQ *)
1173 ndefinition setweak_irq_flag ≝
1174 λm:mcu_type.λt:memory_impl.λs:any_status m t.λirqfl':bool.
1175 match set_irq_flag m t s irqfl' with
1176 [ None ⇒ s | Some s' ⇒ s' ].
1178 (* ***************** *)
1179 (* CONFRONTO FRA ALU *)
1180 (* ***************** *)
1182 (* confronto registro per registro dell'HC05 *)
1183 ndefinition eq_alu_HC05 ≝
1184 λalu1,alu2:alu_HC05.
1186 [ mk_alu_HC05 acclow1 indxlow1 sp1 spm1 spf1 pc1 pcm1 hfl1 ifl1 nfl1 zfl1 cfl1 irqfl1 ⇒
1188 [ mk_alu_HC05 acclow2 indxlow2 sp2 spm2 spf2 pc2 pcm2 hfl2 ifl2 nfl2 zfl2 cfl2 irqfl2 ⇒
1189 (eq_b8 acclow1 acclow2) ⊗
1190 (eq_b8 indxlow1 indxlow2) ⊗
1192 (eq_w16 spm1 spm2) ⊗
1193 (eq_w16 spf1 spf2) ⊗
1195 (eq_w16 pcm1 pcm2) ⊗
1196 (eq_bool hfl1 hfl2) ⊗
1197 (eq_bool ifl1 ifl2) ⊗
1198 (eq_bool nfl1 nfl2) ⊗
1199 (eq_bool zfl1 zfl2) ⊗
1200 (eq_bool cfl1 cfl2) ⊗
1201 (eq_bool irqfl1 irqfl2) ]].
1203 (* confronto registro per registro dell'HC08 *)
1204 ndefinition eq_alu_HC08 ≝
1205 λalu1,alu2:alu_HC08.
1207 [ mk_alu_HC08 acclow1 indxlow1 indxhigh1 sp1 pc1 vfl1 hfl1 ifl1 nfl1 zfl1 cfl1 irqfl1 ⇒
1209 [ mk_alu_HC08 acclow2 indxlow2 indxhigh2 sp2 pc2 vfl2 hfl2 ifl2 nfl2 zfl2 cfl2 irqfl2 ⇒
1210 (eq_b8 acclow1 acclow2) ⊗
1211 (eq_b8 indxlow1 indxlow2) ⊗
1212 (eq_b8 indxhigh1 indxhigh2) ⊗
1215 (eq_bool vfl1 vfl2) ⊗
1216 (eq_bool hfl1 hfl2) ⊗
1217 (eq_bool ifl1 ifl2) ⊗
1218 (eq_bool nfl1 nfl2) ⊗
1219 (eq_bool zfl1 zfl2) ⊗
1220 (eq_bool cfl1 cfl2) ⊗
1221 (eq_bool irqfl1 irqfl2) ]].
1223 (* confronto registro per registro dell'RS08 *)
1224 ndefinition eq_alu_RS08 ≝
1225 λalu1,alu2:alu_RS08.
1227 [ mk_alu_RS08 acclow1 pc1 pcm1 spc1 xm1 psm1 zfl1 cfl1 ⇒
1229 [ mk_alu_RS08 acclow2 pc2 pcm2 spc2 xm2 psm2 zfl2 cfl2 ⇒
1230 (eq_b8 acclow1 acclow2) ⊗
1232 (eq_w16 pcm1 pcm2) ⊗
1233 (eq_w16 spc1 spc2) ⊗
1236 (eq_bool zfl1 zfl2) ⊗
1237 (eq_bool cfl1 cfl2) ]].
1239 (* ******************** *)
1240 (* CONFRONTO FRA STATUS *)
1241 (* ******************** *)
1243 (* confronto di una regione di memoria [addr1 ; ... ; addrn] *)
1244 nlet rec forall_memory_ranged
1246 (chk1:aux_chk_type t) (chk2:aux_chk_type t)
1247 (mem1:aux_mem_type t) (mem2:aux_mem_type t)
1248 (addrl:list word16) on addrl ≝
1249 match addrl return λ_.bool with
1251 | cons hd tl ⇒ (eq_option byte8 (mem_read t mem1 chk1 hd)
1252 (mem_read t mem2 chk2 hd) eq_b8) ⊗
1253 (forall_memory_ranged t chk1 chk2 mem1 mem2 tl)
1256 (* il clk e' option (Prod5T byte8 (any_opcode m) (instr_mode) byte8 word16) *)
1257 ndefinition eq_clk ≝
1258 λm:mcu_type.λc1,c2:option (Prod5T byte8 (any_opcode m) (instr_mode) byte8 word16).
1260 [ None ⇒ match c2 with
1261 [ None ⇒ true | Some _ ⇒ false ]
1262 | Some c1' ⇒ match c2 with
1263 [ None ⇒ false | Some c2' ⇒ (eq_b8 (fst5T ????? c1') (fst5T ????? c2')) ⊗
1264 (eq_anyop m (snd5T ????? c1') (snd5T ????? c2')) ⊗
1265 (eq_instrmode (thd5T ????? c1') (thd5T ????? c2')) ⊗
1266 (eq_b8 (frth5T ????? c1') (frth5T ????? c2')) ⊗
1267 (eq_w16 (ffth5T ????? c1') (ffth5T ????? c2')) ]
1270 (* generalizzazione del confronto fra stati *)
1271 ndefinition eq_status ≝
1272 λm:mcu_type.λt:memory_impl.λs1,s2:any_status m t.λaddrl:list word16.
1273 match s1 with [ mk_any_status alu1 mem1 chk1 clk1 ⇒
1274 match s2 with [ mk_any_status alu2 mem2 chk2 clk2 ⇒
1276 (* 1) confronto della ALU *)
1277 (match m return λm:mcu_type.
1279 [ HC05 ⇒ alu_HC05 | HC08 ⇒ alu_HC08 | HCS08 ⇒ alu_HC08 | RS08 ⇒ alu_RS08 ] →
1281 [ HC05 ⇒ alu_HC05 | HC08 ⇒ alu_HC08 | HCS08 ⇒ alu_HC08 | RS08 ⇒ alu_RS08 ] →
1283 [ HC05 ⇒ eq_alu_HC05 | HC08 ⇒ eq_alu_HC08 | HCS08 ⇒ eq_alu_HC08 | RS08 ⇒ eq_alu_RS08 ]
1286 (* 2) confronto della memoria in [inf,inf+n] *)
1287 (forall_memory_ranged t chk1 chk2 mem1 mem2 addrl) ⊗
1289 (* 3) confronto del clik *)
1290 (eq_clk m clk1 clk2)