source: src/joint/SemanticUtils.ma @ 1415

Last change on this file since 1415 was 1415, checked in by sacerdot, 8 years ago
  1. hwreg_store/retrieve no longer returns a res (but it is still axiomatized)
  2. added initialization of local environment that sets the sp in the appropriate way
  3. ASM/I8051 splitted into ASM/I8051bis because of some bugs with disambiguation
File size: 3.6 KB
Line 
1include "joint/semantics.ma".
2include alias "common/Identifiers.ma".
3
4(*** Store/retrieve on pseudo-registers ***)
5
6axiom BadRegister : String.
7
8definition reg_store ≝ λreg,v,locals. update RegisterTag beval locals reg v.
9
10definition reg_retrieve : register_env beval → register → res beval ≝
11 λlocals,reg. opt_to_res … [MSG BadRegister; CTX ? reg] (lookup … locals reg).
12
13(*** Store/retrieve on hardware registers ***)
14
15axiom hw_register_env: Type[0]. (* CSC: use the one in I8051? *)
16axiom empty_hw_register_env: hw_register_env.
17axiom hwreg_retrieve : hw_register_env → Register → beval.
18axiom hwreg_store : Register → beval → hw_register_env → hw_register_env.
19
20definition init_hw_register_env: address → hw_register_env ≝
21 λaddr.
22  let 〈dpl,dph〉 ≝ addr in
23  let env ≝ hwreg_store RegisterDPH dph empty_hw_register_env in
24   hwreg_store RegisterDPL dpl env.
25
26(****************************************************************************)
27
28(*CSC: XXXXXXXXXXXXXXXXX bug here; we need to change the encoding so that
29  the block is the one of the function and the offset corresponds to the
30  label. Code pointer arithmetics must be prevented in another way, i.e.
31  by not allowing any increment/decrement on Code regions (with the
32  exception of LIN's succ_pc function). If we don't do that, then the
33  find_funct_ptr (e.g. in graph_fetch_statement) are not correct! *)
34(*CSC: XXXX; do we need to create a brand new chunk per label, so that
35  pointer operations on labels are not semantically valid?
36  ATM, the pointers are not valid (they do not point to allocated regions)
37  and, moreover, they conflict with function blocks and with other pointers
38  in other functions. However, there could be simpler ways to invalidate
39  pointer arithmetics on Code pointers.
40*)
41definition pointer_of_label: label → Σp:pointer. ptype p = Code ≝
42 λl.
43  mk_pointer Code
44   (mk_block Code (Zopp (nat_of_bitvector ? (word_of_identifier … l))))
45   ? (mk_offset OZ).
46// qed.
47
48(*CSC: XXXX; inverse of the previous function, but it does not check that
49  the offset is zero and thus it never fails. *)
50definition label_of_pointer: pointer → res label ≝
51 λp. OK … (an_identifier ? (bitvector_of_nat … (abs (block_id (pblock p))))).
52
53(*CSC: XXX This code is cut&paste from joint/semantics.ma, address_of_label.
54 But I can't use it directly because this one uses a concrete definition of
55 pointer_of_label and it is used to istantiate the more_sem_params record
56 where the abstract version is declared as a field. Is there a better way
57 to organize the code? *)
58definition graph_succ_p: label → address → res address ≝
59 λl.λ_.address_of_pointer (pointer_of_label l).
60
61axiom BadProgramCounter: String.
62
63definition graph_fetch_function:
64 ∀params1,sem_params,globals.
65  genv … (graph_params params1 globals) →
66   state sem_params → res (joint_internal_function … (graph_params params1 globals)) ≝
67 λparams1,sem_params,globals,ge,st.
68  do p ← code_pointer_of_address (pc … st) ;
69  let b ≝ pblock p in
70  do def ← opt_to_res ? [MSG BadProgramCounter] (find_funct_ptr … ge b) ;
71  match def with
72  [ Internal def' ⇒ OK … def'
73  | External _ ⇒ Error … [MSG BadProgramCounter]].
74
75definition graph_fetch_statement:
76 ∀params1,sem_params,globals.
77  genv … (graph_params params1 globals) →
78   state sem_params → res (joint_statement (graph_params_ params1) globals) ≝
79 λparams1,sem_params,globals,ge,st.
80  do p ← code_pointer_of_address (pc … st) ;
81  do f ← graph_fetch_function … ge st ;
82  do l ← label_of_pointer p;
83  opt_to_res ? [MSG BadProgramCounter] (lookup ?? (joint_if_code … f) l).
Note: See TracBrowser for help on using the repository browser.