Skip to content

Commit 7366156

Browse files
committed
Add the fault check functionality related to pte value.
- add `check_fault` and `check_value` fields in `node` structure in `cycle.ml`, ,with default values being `None` for irrelevance. `check_fault` carries a boolean and a string, that is, if the event should fault and a label for the instruction. While `check_value` carries a boolean for if any memory effect check, i.e. read event, should be check. This two new variables enable generating fault and value check when there is previous change to pte or plain values respectively. - Introduce `can_fault` function in `Pteval`, which currently check if `valid` is set, i.e., being 1, in AArch64, while always returns `true` for other platform. - Introduce FaultSet of element of an optional label string and a variable string. This replace the StringSet used in the `final.ml` for printing the fault-related post- condition such as `fault(P1:L02,y)`. - Modify `AArch64Compile_gen.ml` for printing the label on load and store instruction, when a fault check is needed. Minor improvement: - Merge the accumulators `cell` and `pte_cell` into CoSt `st` in cycle (`cycle.ml`) building, functions `do_set_write_v` and `do_set_read_v`. - Replace a few manual list foldings with a `List.fold_left`. - Add some explanatory comments on some single-latter variables.
1 parent 7ae3e96 commit 7366156

7 files changed

Lines changed: 438 additions & 294 deletions

File tree

gen/AArch64Arch_gen.ml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,11 @@ let overwrite_value v ao w = match ao with
588588
match a with
589589
| Pte f,None -> do_setpteval a f p
590590
| _ -> Warn.user_error "Atom %s is not a pteval write" (pp_atom a)
591+
592+
let can_fault pte_val =
593+
let open AArch64PteVal in
594+
pte_val.valid = 0
595+
591596
end
592597

593598
(* Wide accesses *)

gen/AArch64Compile_gen.ml

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1725,7 +1725,19 @@ module Make(Cfg:Config) : XXXCompile_gen.S =
17251725

17261726
let get_tagged_loc e = add_tag (as_data e.C.loc) e.C.tag
17271727

1728-
let emit_access st p init e =
1728+
let add_label_to_instructions e cs =
1729+
match e.C.check_fault with
1730+
| Some (label_name, _) ->
1731+
(* Always label the last instruction,
1732+
which should be the actual load or store. *)
1733+
let rec do_rec = function
1734+
| [] -> assert false (* the `cs` should not be empty *)
1735+
| [instr] -> [Label(label_name, instr)]
1736+
| instr::rem -> instr::do_rec rem in
1737+
do_rec cs
1738+
| None -> cs
1739+
1740+
let emit_access st p init e =
17291741
(* collapse the value `v` in event `e` to integer *)
17301742
let value = Code.value_to_int e.C.v in
17311743
match e.C.dir,e.C.loc with
@@ -1759,12 +1771,12 @@ module Make(Cfg:Config) : XXXCompile_gen.S =
17591771
assert (Misc.is_none m) ;
17601772
Some (a,Some (MachSize.S128,0))
17611773
| _ -> Some (a,m) end in
1762-
begin match d,atom with
1774+
let regs,inits,cs,st = begin match d,atom with
17631775
| R,None ->
17641776
let r,init,cs,st = LDR.emit_load st p init loc in
17651777
Some r,init,cs,st
17661778
| R,Some (Acq _,None) ->
1767-
let r,init,cs,st = LDAR.emit_load st p init loc in
1779+
let r,init,cs,st = LDAR.emit_load st p init loc in
17681780
Some r,init,cs,st
17691781
| R,Some (Acq a,Some (sz,o)) ->
17701782
let module L =
@@ -1780,7 +1792,7 @@ module Make(Cfg:Config) : XXXCompile_gen.S =
17801792
let cs2 = emit_ldr_addon a r in
17811793
Some r,init,cs@pseudo cs2,st
17821794
| R,Some (AcqPc _,None) ->
1783-
let r,init,cs,st = LDAPR.emit_load st p init loc in
1795+
let r,init,cs,st = LDAPR.emit_load st p init loc in
17841796
Some r,init,cs,st
17851797
| R,Some (AcqPc a,Some (sz,o)) ->
17861798
let module L =
@@ -1929,7 +1941,10 @@ module Make(Cfg:Config) : XXXCompile_gen.S =
19291941
let init,cs,st = emit_store st p init loc value in
19301942
None,init,cs,st
19311943
| W,Some (Neon _,Some _) -> assert false
1932-
end
1944+
end in
1945+
(* Add a label to instructions `cs`, when a fault check is required. *)
1946+
let cs = add_label_to_instructions e cs in
1947+
regs,inits,cs,st
19331948
(* END of emit_access *)
19341949

19351950
let same_sz sz1 sz2 = match sz1,sz2 with

gen/archExtra_gen.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ module type S = sig
6262

6363
(* complete init with necessary information *)
6464
val complete_init : bool (* hexa *) -> Code.env -> init -> init
65+
val pp_env: init -> string
6566

6667

6768
(***********************)
@@ -181,7 +182,7 @@ and type special3 = I.special3
181182
| None -> "-"
182183
| Some v -> pp_initval v
183184

184-
let _pp_env env =
185+
let pp_env env =
185186
String.concat ", "
186187
(List.map (fun (loc,v) -> pp_location loc ^ "->" ^ ppo v) env)
187188

0 commit comments

Comments
 (0)