source: src/ERTL/semantics.ma @ 1390

Last change on this file since 1390 was 1390, checked in by sacerdot, 9 years ago

All fetch_result implementations have been factorized out, leaving only a
result_regs function. All axioms in joint_LTL_LIN_semantics but the ones for
external functions have been implemented.

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