Skip to content

Commit aed16c6

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 d659a5c commit aed16c6

11 files changed

Lines changed: 575 additions & 347 deletions

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: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1725,6 +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 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 length = List.length cs in
1734+
List.mapi
1735+
( fun index instr ->
1736+
if index = (length - 1) then
1737+
Label(label_name, instr)
1738+
else instr ) cs
1739+
| None -> cs
1740+
17281741
let emit_access st p init e = match e.C.dir,e.C.loc with
17291742
| None,_ -> Warn.fatal "AArchCompile.emit_access"
17301743
| Some d,Code lab ->
@@ -1756,12 +1769,18 @@ module Make(Cfg:Config) : XXXCompile_gen.S =
17561769
assert (Misc.is_none m) ;
17571770
Some (a,Some (MachSize.S128,0))
17581771
| _ -> Some (a,m) end in
1759-
begin match d,atom with
1772+
(* Compile the node.
1773+
- `regs`, registers
1774+
- `inits`, initial values
1775+
- `cs`, instructions
1776+
- `st`, states
1777+
*)
1778+
let regs,inits,cs,st = begin match d,atom with
17601779
| R,None ->
17611780
let r,init,cs,st = LDR.emit_load st p init loc in
17621781
Some r,init,cs,st
17631782
| R,Some (Acq _,None) ->
1764-
let r,init,cs,st = LDAR.emit_load st p init loc in
1783+
let r,init,cs,st = LDAR.emit_load st p init loc in
17651784
Some r,init,cs,st
17661785
| R,Some (Acq a,Some (sz,o)) ->
17671786
let module L =
@@ -1777,7 +1796,7 @@ module Make(Cfg:Config) : XXXCompile_gen.S =
17771796
let cs2 = emit_ldr_addon a r in
17781797
Some r,init,cs@pseudo cs2,st
17791798
| R,Some (AcqPc _,None) ->
1780-
let r,init,cs,st = LDAPR.emit_load st p init loc in
1799+
let r,init,cs,st = LDAPR.emit_load st p init loc in
17811800
Some r,init,cs,st
17821801
| R,Some (AcqPc a,Some (sz,o)) ->
17831802
let module L =
@@ -1926,7 +1945,11 @@ module Make(Cfg:Config) : XXXCompile_gen.S =
19261945
let init,cs,st = emit_store st p init loc e.C.v in
19271946
None,init,cs,st
19281947
| W,Some (Neon _,Some _) -> assert false
1929-
end
1948+
end in
1949+
(* Add a label to instructions `cs`, when a fault check is required. *)
1950+
let cs = add_label_to_instructions e cs in
1951+
regs,inits,cs,st
1952+
(* END of emit_access *)
19301953

19311954
let same_sz sz1 sz2 = match sz1,sz2 with
19321955
| None,None -> true

gen/FaultSetElm.ml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
(****************************************************************************)
2+
(* The diy toolsuite *)
3+
(* *)
4+
(* Jade Alglave, University College London, UK. *)
5+
(* Luc Maranget, INRIA Paris-Rocquencourt, France. *)
6+
(* *)
7+
(* Copyright 2025-present Institut National de Recherche en Informatique et *)
8+
(* en Automatique, ARM Ltd and the authors. All rights reserved. *)
9+
(* *)
10+
(* This software is governed by the CeCILL-B license under French law and *)
11+
(* abiding by the rules of distribution of free software. You can use, *)
12+
(* modify and/ or redistribute the software under the terms of the CeCILL-B *)
13+
(* license as circulated by CEA, CNRS and INRIA at the following URL *)
14+
(* "http://www.cecill.info". We also give a copy in LICENSE.txt. *)
15+
(****************************************************************************)
16+
17+
type t = string option * bool option * string
18+
19+
let compare (lhs_label, lhs_bool, lhs_var) (rhs_label, rhs_bool, rhs_var) =
20+
let label =
21+
Option.compare String.compare lhs_label rhs_label in
22+
let boolean =
23+
Option.compare Bool.compare lhs_bool rhs_bool in
24+
match label, boolean with
25+
| 0, 0 -> String.compare lhs_var rhs_var
26+
| 0, boolean -> boolean
27+
| label, _ -> label

gen/PPCCompile_gen.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ module Make(O:Config)(C:sig val eieio : bool end) : XXXCompile_gen.S =
450450
let emit = match e.atom with
451451
| None -> emit_load
452452
| Some (PPC.Mixed (sz,o)) -> emit_load_mixed sz o
453-
| Some PPC.Reserve ->emit_lwarx
453+
| Some PPC.Reserve -> emit_lwarx
454454
| Some PPC.Atomic -> emit_lda in
455455
let r,init,cs,st = emit st p init loc in
456456
Some r,init,(if isync then insert_isync c cs else c@cs),st

gen/RISCVCompile_gen.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ module Make(Cfg:Config) : XXXCompile_gen.S =
221221

222222
(* For export *)
223223
let emit_load_one = LOAD.emit_load_one AV.Rlx
224-
let emit_load = LOAD.emit_load AV.Rlx
224+
let emit_load = LOAD.emit_load AV.Rlx
225225
let emit_obs _ = OBS.emit_load AV.Rlx
226226
let emit_obs_not_value = OBS.emit_load_not_value AV.Rlx
227227
let emit_obs_not_eq = OBS.emit_load_not_eq AV.Rlx

gen/X86_64Compile_gen.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ module Make(Cfg:CompileCommon.Config) : XXXCompile_gen.S =
324324
| R ->
325325
begin match e.C.atom with
326326
| None|Some (Plain,None) ->
327-
let r,init,cs,st = emit_load st _p init loc in
327+
let r,init,cs,st = emit_load st _p init loc in
328328
Some r,init, cs,st
329329
| Some (Atomic,_) ->
330330
Warn.fatal "No atomic load for X86_64"

gen/archExtra_gen.ml

Lines changed: 18 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
(***********************)
@@ -150,6 +151,8 @@ and type special3 = I.special3
150151
let of_loc loc = Loc (Code.as_data loc)
151152
let of_reg p r = Reg (p,r)
152153

154+
(* - S of a plain value, a pte_* address or a phy_* address
155+
- P of a PteVal *)
153156
type initval = S of string | P of AArch64PteVal.t
154157
let pp_initval = function
155158
| S v -> pp_symbol v
@@ -162,11 +165,15 @@ and type special3 = I.special3
162165

163166
type init = (location * initval option) list
164167

168+
(* convert to `Some`, if input `s`
169+
is not a pteval nor a number *)
165170
let as_virtual s = match Misc.tr_pte s with
166171
| Some _ -> None
167172
| None ->
168173
if LexScan.is_num s then None else Some s
169174

175+
(* convert to `Some`, if input `s`
176+
is neither a pteval or a physical location *)
170177
let refers_virtual s = match Misc.tr_pte s with
171178
| Some _ as r -> r
172179
| None -> match Misc.tr_physical s with
@@ -181,21 +188,25 @@ and type special3 = I.special3
181188
| None -> "-"
182189
| Some v -> pp_initval v
183190

184-
let _pp_env env =
191+
let pp_env env =
185192
String.concat ", "
186193
(List.map (fun (loc,v) -> pp_location loc ^ "->" ^ ppo v) env)
187194

188195
let complete_init hexa iv i =
189196
let i =
197+
(* Add the locs `loc` and values `v` inside `iv` to `i` *)
190198
List.fold_left
191199
(fun env (loc,v) -> (Loc loc,Some (S (Code.pp_v ~hexa:hexa v)))::env) i iv in
192200
let already_here =
193201
List.fold_left
194202
(fun k (loc,v) ->
195203
let k = match loc with
204+
(* Add Loc `s` into `k` if `s` is not a pte address nor a number *)
196205
| Loc s -> add_some (as_virtual s) k
206+
(* No process on register *)
197207
| Reg _ -> k in
198208
let k = match v with
209+
(* Add value `s` into `k` if `s` is not a pte nor a number *)
199210
| Some (S s) -> add_some (as_virtual s) k
200211
| _ -> k in
201212
k)
@@ -204,16 +215,22 @@ and type special3 = I.special3
204215
List.fold_left
205216
(fun k (loc,v) ->
206217
let k = match loc with
218+
(* Add Loc `s` into `k` if `s` is a pte or physical address *)
207219
| Loc s -> add_some (refers_virtual s) k
220+
(* No process on register *)
208221
| Reg _ -> k in
209222
let k = match v with
223+
(* Add value `s` into `k` if `s` is a pte or physical address *)
210224
| Some (S s) -> add_some (refers_virtual s) k
225+
(* Add the associated physical address in a pteval `p` into `k` *)
211226
| Some (P p) ->
212227
add_some
213228
(OutputAddress.refers_virtual p.AArch64PteVal.oa) k
214229
| None -> k in
215230
k)
216231
StringSet.empty i in
232+
(* If a `refer` exist but there is no entry,
233+
then add it into init state `i` *)
217234
let i =
218235
StringSet.fold
219236
(fun x i -> (Loc x,None)::i)

0 commit comments

Comments
 (0)