]> matita.cs.unibo.it Git - helm.git/blob - helm/software/matita/contribs/ng_assembly/emulator/read_write/fetch.ma
mod change (-x)
[helm.git] / helm / software / matita / contribs / ng_assembly / emulator / read_write / fetch.ma
1 (**************************************************************************)
2 (*       ___                                                              *)
3 (*      ||M||                                                             *)
4 (*      ||A||       A project by Andrea Asperti                           *)
5 (*      ||T||                                                             *)
6 (*      ||I||       Developers:                                           *)
7 (*      ||T||         The HELM team.                                      *)
8 (*      ||A||         http://helm.cs.unibo.it                             *)
9 (*      \   /                                                             *)
10 (*       \ /        This file is distributed under the terms of the       *)
11 (*        v         GNU General Public License Version 2                  *)
12 (*                                                                        *)
13 (**************************************************************************)
14
15 (* ********************************************************************** *)
16 (*                          Progetto FreeScale                            *)
17 (*                                                                        *)
18 (*   Sviluppato da: Ing. Cosimo Oliboni, oliboni@cs.unibo.it              *)
19 (*   Sviluppo: 2008-2010                                                  *)
20 (*                                                                        *)
21 (* ********************************************************************** *)
22
23 include "emulator/memory/memory_abs.ma".
24 include "emulator/translation/translation.ma".
25 include "emulator/status/status_getter.ma".
26
27 (* errori possibili nel fetch OPCODE / ILLEGAL ADDRESS *)
28 ninductive error_type : Type ≝
29   ILL_OP: error_type
30 | ILL_FETCH_AD: error_type
31 .
32
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.
38
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
44   ].
45
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
51   ].
52
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 ].
59
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〉
69     ]
70    | false ⇒ fetch_byte_aux m (succ_w16 pc) bh
71    ]
72   ].
73
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〉
85     ]
86    | false ⇒ fetch_byte_aux m (succ_w16 pc) bh
87    ]
88   ].
89
90 ndefinition fetch ≝
91 λm:mcu_type.λt:memory_impl.λs:any_status m t.
92  match m with
93   [ HC05 ⇒ fetch_byte
94   | HC08 ⇒ Freescale_fetch_byte_or_word
95   | HCS08 ⇒ Freescale_fetch_byte_or_word
96   | RS08 ⇒ fetch_byte
97   | IP2022 ⇒ IP2022_fetch_byte_or_word
98   ] m (mem_read t (mem_desc … s) (chk_desc … s)) (get_pc_reg … s).