source: src/ERTL/semantics_paolo.ma @ 2208

Last change on this file since 2208 was 2208, checked in by tranquil, 7 years ago
  • moving some code around
  • changed immediates to hold beval in general, not only bytes
  • fixed RTLabsToRTL after redefinitions in front end
File size: 5.5 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  OK … 〈\fst local_env,hwreg_store r v (\snd local_env)〉.
16
17definition hw_reg_retrieve ≝
18 λlocal_env:(register_env beval) × hw_register_env.λreg.
19  OK … (hwreg_retrieve … (\snd local_env) reg).
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)
24   (λsp.〈empty_map …,init_hw_register_env sp〉) 0 it
25   ps_reg_store ps_reg_retrieve ps_reg_store ps_reg_retrieve ps_reg_store ps_reg_retrieve
26    ps_reg_store ps_reg_retrieve ps_reg_store ps_reg_retrieve
27     (λlocals,dest_src.
28       do v ←
29        match \snd dest_src with
30        [ pseudo reg ⇒ ps_reg_retrieve locals reg
31        | hardware reg ⇒ hw_reg_retrieve locals reg] ;
32       match \fst dest_src with
33       [ pseudo reg ⇒ ps_reg_store reg v locals
34       | hardware reg ⇒ hw_reg_store reg v locals]).
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 → address ≝
79 λst.
80  let spl ≝ hwreg_retrieve (\snd (regs … st)) RegisterSPL in
81  let sph ≝ hwreg_retrieve (\snd (regs … st)) RegisterSPH in
82   〈spl,sph〉.
83
84definition set_hwsp : address → state ertl_sem_params → state ertl_sem_params ≝
85 λsp,st.
86  let 〈spl,sph〉 ≝ sp in
87  let hwregs ≝ hwreg_store RegisterSPL spl (\snd (regs … st)) in
88  let hwregs ≝ hwreg_store RegisterSPH sph hwregs in
89  set_regs ertl_sem_params 〈\fst (regs … st),hwregs〉 st.
90
91definition ertl_more_sem_params1: ∀globals. more_sem_params1 … (ertl_params globals) ≝
92 λglobals.
93  mk_more_sem_params1 … ertl_more_sem_params graph_succ_p (graph_pointer_of_label …)
94    (graph_fetch_statement …) (load_ra …) (ertl_result_regs …)
95    ertl_init_locals ertl_save_frame (ertl_pop_frame …)
96    ertl_fetch_external_args ertl_set_result.
97definition ertl_sem_params1: ∀globals. sem_params1 globals ≝
98 λglobals. mk_sem_params1 … (ertl_more_sem_params1 globals).
99
100definition ertl_exec_extended:
101 ∀globals. genv globals (ertl_params globals) →
102  ertl_statement_extension → label → state ertl_sem_params →
103   IO io_out io_in (trace × (state ertl_sem_params)) ≝
104 λglobals,ge,stm,l,st.
105  match stm with
106   [ ertl_st_ext_new_frame ⇒
107      ! v ← framesize globals … ge st;
108      let sp ≝ get_hwsp st in
109      ! newsp ← addr_sub sp v;
110      let st ≝ set_hwsp newsp st in
111      ! st ← next … (ertl_sem_params1 globals) l st ;
112        return 〈E0,st〉
113   | ertl_st_ext_del_frame ⇒
114      ! v ← framesize … ge st;
115      let sp ≝ get_hwsp st in
116      ! newsp ← addr_add sp v;
117      let st ≝ set_hwsp newsp st in
118      ! st ← next … (ertl_sem_params1 …) l st ;
119        return 〈E0,st〉
120   | ertl_st_ext_frame_size dst ⇒
121      ! v ← framesize … ge st;
122      ! st ← greg_store ertl_sem_params dst (BVByte (bitvector_of_nat … v)) st;
123      ! st ← next … (ertl_sem_params1 …) l st ;
124        return 〈E0, st〉
125   ].
126
127definition ertl_more_sem_params2: ∀globals. more_sem_params2 … (ertl_params globals) ≝
128 λglobals. mk_more_sem_params2 … (ertl_more_sem_params1 …) (ertl_exec_extended …).
129
130definition ertl_fullexec: fullexec io_out io_in ≝
131 joint_fullexec … (λp. ertl_more_sem_params2 (prog_var_names … p)).
Note: See TracBrowser for help on using the repository browser.