Skip to content

Commit b0a7879

Browse files
committed
Apply code reviews
1 parent 5a987d8 commit b0a7879

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

ArchSemArm/VMPromising.v

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,6 @@ Definition strict_regs : gset reg :=
388388
SP_EL1;
389389
SP_EL2;
390390
SP_EL3;
391-
PSTATE;
392391
ELR_EL1;
393392
ELR_EL2;
394393
ELR_EL3;
@@ -709,8 +708,9 @@ Definition va_to_vpn {n : N} (va : bv 64) : bv n :=
709708
bv_extract 12 n va.
710709

711710
Definition prefix_to_va {n : N} (is_upper : bool) (p : bv n) : bv 64 :=
712-
let varange_bit := if is_upper then (bv_1 16) else (bv_0 16) in
713-
bv_concat 64 varange_bit (bv_concat 48 p (bv_0 (48 - n))).
711+
let varange_bits : bv 16 := if is_upper then (-1)%bv else 0%bv in
712+
let padding := bv_0 (48 - n) in
713+
bv_concat 64 varange_bits (bv_concat 48 p padding).
714714

715715
Definition is_upper_va (va : bv 64) : option bool :=
716716
let top_bits := bv_extract 48 16 va in
@@ -801,9 +801,9 @@ Module TLB.
801801
Definition t := {lvl : Level & NDCtxt.t lvl}.
802802
Definition lvl : t -> Level := projT1.
803803
Definition nd (ctxt : t) : NDCtxt.t (lvl ctxt) := projT2 ctxt.
804+
Definition is_upper (ctxt : t) : bool := NDCtxt.is_upper (nd ctxt).
804805
Definition va (ctxt : t) : prefix (lvl ctxt) := NDCtxt.va (nd ctxt).
805806
Definition asid (ctxt : t) : option (bv 16) := NDCtxt.asid (nd ctxt).
806-
Definition is_upper (ctxt : t) : bool := NDCtxt.is_upper (nd ctxt).
807807
End Ctxt.
808808
#[export] Typeclasses Transparent Ctxt.t.
809809

@@ -831,7 +831,7 @@ Module TLB.
831831
Definition pte {lvl} (tlbe : t lvl) := Vector.last tlbe.(ptes).
832832

833833
Program Definition append {lvl clvl : Level}
834-
(tlbe : @t lvl)
834+
(tlbe : t lvl)
835835
(pte : val)
836836
(CHILD : lvl + 1 = clvl) : @t clvl :=
837837
make _ tlbe.(val_ttbr) (ctrans _ (tlbe.(ptes) +++ [#pte])).
@@ -1228,7 +1228,7 @@ Module TLB.
12281228
mret ((Entry.val_ttbr te), (vec_to_list (Entry.ptes te)), ti)
12291229
end.
12301230

1231-
(** Get all the TLB entries and the corresponding TTBR value that
1231+
(** Get all the TLB entries (including the TTBR value) TTBR value that
12321232
could translate the given VA at the provided level
12331233
and in the provided ASID context.
12341234
Return each TLB entry as a list of descriptors [list val] with
@@ -1239,7 +1239,7 @@ Module TLB.
12391239
(lvl : Level)
12401240
(va : bv 64) (asid : bv 16) :
12411241
result string (list (val * list val * (option nat))) :=
1242-
is_upper ← othrow ("VA is not in the range: " ++ (pretty va))%string
1242+
is_upper ← othrow ("VA is not in the 48 bits range: " ++ (pretty va))%string
12431243
(is_upper_va va);
12441244
let ndctxt_asid := NDCtxt.make is_upper (level_prefix va lvl) (Some asid) in
12451245
let ndctxt_global := NDCtxt.make is_upper (level_prefix va lvl) None in
@@ -1535,9 +1535,10 @@ Definition run_reg_trans_read (reg : reg) (racc : reg_acc)
15351535
mret (ctrans eq root.T2, 0%nat)
15361536
else
15371537
ts ← mGet;
1538+
(* We are only allowed to read registers that are never written during the translation *)
15381539
guard_or
15391540
("The register should niether be relaxed nor strict: " ++ pretty reg)%string
1540-
$ (reg ∉ strict_regs reg ∉ relaxed_regs);;
1541+
$ (reg ∉ strict_regs reg ∉ relaxed_regs);;
15411542
othrow
15421543
("Register " ++ pretty reg ++ " unmapped; cannot read")%string
15431544
$ TState.read_reg ts reg.
@@ -1841,6 +1842,7 @@ Definition run_trans_start (trans_start : TranslationStartInfo)
18411842
"TTBR value type does not match with the value from the translation"
18421843
(val_to_regval ttbr val_ttbr);
18431844
let root := (Some (existT ttbr val_ttbr)) in
1845+
let ti := if is_ifetch then ti else None in
18441846
mret $ (IIS.TransRes.make (va_to_vpn va) t root path, ti)
18451847
end;
18461848
invalid_res ←
@@ -1883,7 +1885,7 @@ Definition run_trans_end (trans_end : trans_end) :
18831885
let trans_time := trs.(IIS.TransRes.time) in
18841886
let fault := trans_end.(AddressDescriptor_fault) in
18851887
if decide (fault.(FaultRecord_statuscode) = Fault_None) then
1886-
mset snd $ setv IIS.trs None
1888+
msetv (IIS.trs ∘ snd) None
18871889
else
18881890
is_ets3 ← mlift (ets3 ts);
18891891
if is_ets3 && (trans_time <? (ts.(TState.vrd) ⊔ ts.(TState.vwr)))
@@ -1901,21 +1903,18 @@ Definition run_trans_end (trans_end : trans_end) :
19011903
let is_rel := fault.(FaultRecord_access).(AccessDescriptor_relsc) in
19021904
write_view ← write_fault_vpre is_rel trans_time;
19031905
mset snd $ IIS.add (view_if is_write write_view);;
1904-
mset snd $ setv IIS.trs None
1906+
msetv (IIS.trs ∘ snd) None
19051907
else
19061908
mthrow "Translation ends with an empty translation".
19071909

19081910
(* TODO: check translation fault using `fault` and handle other cases *)
19091911
Definition run_take_exception (fault : exn) (vmax_t : view) :
19101912
Exec.t (TState.t * IIS.t) string () :=
19111913
iis ← mget snd;
1912-
if iis.(IIS.trs) is Some trans_res then
1913-
match iis.(IIS.inv_time) with
1914-
| Some inv_time => run_cse inv_time
1915-
| None => mret ()
1916-
end
1917-
else
1918-
run_cse vmax_t.
1914+
match iis.(IIS.inv_time) with
1915+
| Some inv_time => run_cse inv_time
1916+
| None => run_cse vmax_t
1917+
end.
19191918

19201919
(** Runs an outcome. *)
19211920
Section RunOutcome.

0 commit comments

Comments
 (0)