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 (* Sviluppo: 2008-2010 *)
21 (* ********************************************************************** *)
23 include "emulator/memory/memory_abs.ma".
24 include "emulator/translation/translation.ma".
25 include "emulator/status/status_getter.ma".
27 (* errori possibili nel fetch OPCODE / ILLEGAL ADDRESS *)
28 ninductive error_type : Type ≝
30 | ILL_FETCH_AD: error_type
33 (* - errore: interessa solo l'errore
34 - ok: interessa info, nuovo pc *)
35 ninductive fetch_result (A:Type) : Type ≝
36 FetchERR : error_type → fetch_result A
37 | FetchOK : A → word16 → fetch_result A.
39 ndefinition fetch_byte_aux ≝
40 λm:mcu_type.λcur_pc:word16.λbh:byte8.
41 match full_info_of_word16 m (Byte bh) with
42 [ None ⇒ FetchERR ? ILL_FETCH_AD
43 | Some info ⇒ FetchOK ? info cur_pc
46 ndefinition fetch_word_aux ≝
47 λm:mcu_type.λcur_pc:word16.λw:word16.
48 match full_info_of_word16 m (Word w) with
49 [ None ⇒ FetchERR ? ILL_FETCH_AD
50 | Some info ⇒ FetchOK ? info cur_pc
53 (* opcode a byte : HC05 / RS08 *)
54 ndefinition fetch_byte ≝
55 λm:mcu_type.λfR:word32 → option byte8.λpc:word16.
56 match fR (extu_w32 pc) with
57 [ None ⇒ FetchERR ? ILL_FETCH_AD
58 | Some bh ⇒ fetch_byte_aux m (succ_w16 pc) bh ].
60 (* opcode a byte o 0x9E + byte : HC08 / HCS08 *)
61 ndefinition Freescale_fetch_byte_or_word ≝
62 λm:mcu_type.λfR:word32 → option byte8.λpc:word16.
63 match fR (extu_w32 pc) with
64 [ None ⇒ FetchERR ? ILL_FETCH_AD
65 | Some bh ⇒ match eq_b8 bh 〈x9,xE〉 with
66 [ true ⇒ match fR (extu_w32 (succ_w16 pc)) with
67 [ None ⇒ FetchERR ? ILL_FETCH_AD
68 | Some bl ⇒ fetch_word_aux m (succ_w16 (succ_w16 pc)) 〈bh:bl〉
70 | false ⇒ fetch_byte_aux m (succ_w16 pc) bh
74 (* opcode a byte o 0x00 + byte : IP2022 *)
75 (* opcode + operando a dimensione fissa 16bit *)
76 (* pc word aligned, mappato in 0x02000000-0x0201FFFF *)
77 ndefinition IP2022_fetch_byte_or_word ≝
78 λm:mcu_type.λfR:word32 → option byte8.λpc:word16.
79 match fR (rol_w32 〈〈〈x0,x1〉:〈x0,x0〉〉.pc〉) with
80 [ None ⇒ FetchERR ? ILL_FETCH_AD
81 | Some bh ⇒ match eq_b8 bh 〈x0,x0〉 with
82 [ true ⇒ match fR (rol_w32 〈〈〈x8,x1〉:〈x0,x0〉〉.pc〉) with
83 [ None ⇒ FetchERR ? ILL_FETCH_AD
84 | Some bl ⇒ fetch_word_aux m (succ_w16 pc) 〈bh:bl〉
86 | false ⇒ fetch_byte_aux m (succ_w16 pc) bh
91 λm:mcu_type.λt:memory_impl.λs:any_status m t.
94 | HC08 ⇒ Freescale_fetch_byte_or_word
95 | HCS08 ⇒ Freescale_fetch_byte_or_word
97 | IP2022 ⇒ IP2022_fetch_byte_or_word
98 ] m (mem_read t (mem_desc … s) (chk_desc … s)) (get_pc_reg … s).