source: src/ERTL/semantics.ma @ 1389

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

One more axiom closed.

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
73definition framesize:
74 ∀globals. genv … (ertl_params globals) → state ertl_sem_params → res nat ≝
75  λglobals,ge,st.
76   do f ← graph_fetch_function … ge st ;
77   OK ? (joint_if_stacksize globals … f).
78
79definition get_hwsp : state ertl_sem_params → res address ≝
80 λst.
81  do spl ← hwreg_retrieve (\snd (regs … st)) RegisterSPL ;
82  do sph ← hwreg_retrieve (\snd (regs … st)) RegisterSPH ;
83  OK ? 〈spl,sph〉.
84
85definition set_hwsp : address → state ertl_sem_params → res (state ertl_sem_params) ≝
86 λsp,st.
87  let 〈spl,sph〉 ≝ sp in
88  do hwregs ← hwreg_store RegisterSPL spl (\snd (regs … st)) ;
89  do hwregs ← hwreg_store RegisterSPH sph hwregs ;
90  OK ? (set_regs ertl_sem_params 〈\fst (regs … st),hwregs〉 st).
91
92definition ertl_exec_extended:
93 ∀globals. genv globals (ertl_params globals) →
94  ertl_statement_extension → label → state ertl_sem_params →
95   IO io_out io_in (trace × (state ertl_sem_params)) ≝
96 λglobals,ge,stm,l,st.
97  match stm with
98   [ ertl_st_ext_new_frame ⇒
99      ! v ← framesize globals … ge st;
100      ! sp ← get_hwsp st;
101      ! newsp ← addr_sub sp v;
102      ! st ← set_hwsp newsp st;
103        ret ? 〈E0,goto … l st〉
104   | ertl_st_ext_del_frame ⇒
105      ! v ← framesize … ge st;
106      ! sp ← get_hwsp st;
107      ! newsp ← addr_add sp v;
108      ! st ← set_hwsp newsp st;
109        ret ? 〈E0,goto … l st〉
110   | ertl_st_ext_frame_size dst ⇒
111      ! v ← framesize … ge st;
112      ! st ← greg_store ertl_sem_params dst (BVByte (bitvector_of_nat … v)) st;
113        ret ? 〈E0, goto … l st〉
114   ].
115
116definition ertl_more_sem_params2: ∀globals. more_sem_params2 … (ertl_params globals) ≝
117 λglobals.
118  mk_more_sem_params2 … ertl_more_sem_params
119   (graph_fetch_statement …) (load_ra …) (ertl_fetch_result …)
120   ertl_init_locals ertl_save_frame (ertl_pop_frame …)
121   ertl_fetch_external_args ertl_set_result (ertl_exec_extended …).
122
123definition ertl_fullexec ≝
124 joint_fullexec … (λp. ertl_more_sem_params2 (prog_var_names … p)).
Note: See TracBrowser for help on using the repository browser.