source: src/ERTL/semantics.ma @ 1388

Last change on this file since 1388 was 1388, checked in by sacerdot, 8 years ago

fetch_result implemented for ERTL. This required a different istantiation of
resultT that is not in line with the OCaml's code. Look at CHANGES for details.
RTLToERTL has been ported in an hopefully correct manner.

File size: 5.0 KB
Line 
1include "joint/SemanticUtils.ma".
2include "ERTL/ERTL.ma". (* CSC: syntax.ma in RTLabs *)
3include alias "common/Identifiers.ma".
4
5definition ps_reg_store ≝
6 λr,v.λlocal_env:(register_env beval) × hw_register_env.
7  do res ← reg_store r v (\fst local_env) ;
8  OK … 〈res, \snd local_env〉.
9
10definition ps_reg_retrieve ≝
11 λlocal_env:(register_env beval) × hw_register_env. reg_retrieve … (\fst local_env).
12
13definition hw_reg_store ≝
14 λr,v.λlocal_env:(register_env beval) × hw_register_env.
15  do res ← hwreg_store r v (\snd local_env) ;
16  OK … 〈\fst local_env,res〉.
17
18definition hw_reg_retrieve ≝
19 λlocal_env:(register_env beval) × hw_register_env. hwreg_retrieve … (\snd local_env).
20
21definition ertl_more_sem_params: more_sem_params ertl_params_ :=
22 mk_more_sem_params ertl_params_
23  (list (register_env beval)) ((register_env beval) × hw_register_env) graph_succ_p
24   ps_reg_store ps_reg_retrieve ps_reg_store ps_reg_retrieve ps_reg_store ps_reg_retrieve
25    ps_reg_store ps_reg_retrieve ps_reg_store ps_reg_retrieve
26     (λlocals,dest_src.
27       do v ←
28        match \snd dest_src with
29        [ pseudo reg ⇒ ps_reg_retrieve locals reg
30        | hardware reg ⇒ hw_reg_retrieve locals reg] ;
31       match \fst dest_src with
32       [ pseudo reg ⇒ ps_reg_store reg v locals
33       | hardware reg ⇒ hw_reg_store reg v locals])
34     pointer_of_label.
35definition ertl_sem_params: sem_params ≝ mk_sem_params … ertl_more_sem_params.
36
37definition ertl_init_locals :
38 list register →
39  (register_env beval) × hw_register_env → (register_env beval) × hw_register_env ≝
40 λlocals,lenv.
41  〈foldl … (λlenv,reg. add … lenv reg BVundef) (empty_map …) locals, \snd lenv〉.
42
43(*CSC: could we use here a dependent type to avoid the Error case? *)
44axiom EmptyStack: String.
45definition ertl_pop_frame:
46 ∀globals. genv … (ertl_params globals) → state … ertl_sem_params → res (state … ertl_sem_params) ≝
47 λglobals,ge,st.
48  let frms ≝ st_frms ? st in
49  match frms with
50  [ nil ⇒ Error ? [MSG EmptyStack]
51  | cons hd tl ⇒
52     OK … (set_frms ertl_sem_params tl (set_regs ertl_sem_params 〈hd, \snd (regs … st)〉 st)) ].
53
54definition ertl_save_frame:
55 address → nat → nat → nat → unit → state … ertl_sem_params → res (state … ertl_sem_params) ≝
56 λl.λ_.λ_.λ_.λ_.λst.
57  do st ← save_ra … st l ;
58  OK …
59   (set_frms ertl_sem_params (\fst (regs … st) :: (st_frms … st))
60    (set_regs ertl_sem_params 〈empty_map …,\snd (regs … st)〉 st)).
61
62definition ertl_fetch_result:
63 ∀globals. genv … (ertl_params globals) → state ertl_sem_params → res (list beval) ≝
64 λglobals,ge,st.
65  do fn ← graph_fetch_function … globals ge st ;
66  let ret_val_regs ≝ joint_if_result … fn in
67   mmap … (λreg.greg_retrieve ertl_sem_params st reg) ret_val_regs.
68
69(*CSC: XXXX, for external functions only*)
70axiom ertl_fetch_external_args: external_function → state ertl_sem_params → res (list val).
71axiom ertl_set_result: list val → state ertl_sem_params → res (state ertl_sem_params).
72
73(*CSC: XXXX *)
74axiom framesize: list ident → state ertl_sem_params → res nat. (* ≝
75  λglobals: list ident.
76  λst.
77   do f ← fetch_function globals st ;
78   OK ? (joint_if_stacksize globals … f).*)
79
80definition get_hwsp : state ertl_sem_params → res address ≝
81 λst.
82  do spl ← hwreg_retrieve (\snd (regs … st)) RegisterSPL ;
83  do sph ← hwreg_retrieve (\snd (regs … st)) RegisterSPH ;
84  OK ? 〈spl,sph〉.
85
86definition set_hwsp : address → state ertl_sem_params → res (state ertl_sem_params) ≝
87 λsp,st.
88  let 〈spl,sph〉 ≝ sp in
89  do hwregs ← hwreg_store RegisterSPL spl (\snd (regs … st)) ;
90  do hwregs ← hwreg_store RegisterSPH sph hwregs ;
91  OK ? (set_regs ertl_sem_params 〈\fst (regs … st),hwregs〉 st).
92
93definition ertl_exec_extended:
94 ∀globals. genv globals (ertl_params globals) →
95  ertl_statement_extension → label → state ertl_sem_params →
96   IO io_out io_in (trace × (state ertl_sem_params)) ≝
97 λglobals,ge,stm,l,st.
98  match stm with
99   [ ertl_st_ext_new_frame ⇒
100      ! v ← framesize globals st;
101      ! sp ← get_hwsp st;
102      ! newsp ← addr_sub sp v;
103      ! st ← set_hwsp newsp st;
104        ret ? 〈E0,goto … l st〉
105   | ertl_st_ext_del_frame ⇒
106      ! v ← framesize globals st;
107      ! sp ← get_hwsp st;
108      ! newsp ← addr_add sp v;
109      ! st ← set_hwsp newsp st;
110        ret ? 〈E0,goto … l st〉
111   | ertl_st_ext_frame_size dst ⇒
112      ! v ← framesize globals st;
113      ! st ← greg_store ertl_sem_params dst (BVByte (bitvector_of_nat … v)) st;
114        ret ? 〈E0, goto … l st〉
115   ].
116
117definition ertl_more_sem_params2: ∀globals. more_sem_params2 … (ertl_params globals) ≝
118 λglobals.
119  mk_more_sem_params2 … ertl_more_sem_params
120   (graph_fetch_statement …) (load_ra …) (ertl_fetch_result …)
121   ertl_init_locals ertl_save_frame (ertl_pop_frame …)
122   ertl_fetch_external_args ertl_set_result (ertl_exec_extended …).
123
124definition ertl_fullexec ≝
125 joint_fullexec … (λp. ertl_more_sem_params2 (prog_var_names … p)).
Note: See TracBrowser for help on using the repository browser.