Skip to content

Commit bab60c1

Browse files
committed
Example use of initial state from Isla
1 parent 72936cc commit bab60c1

File tree

3 files changed

+540
-1
lines changed

3 files changed

+540
-1
lines changed
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
From ASCommon Require Import Options Common.
2+
From ArchSemArm Require Import ArmInst ArmSeqModel IslaInit.
3+
From ASCommon Require Import CResult.
4+
5+
6+
7+
Open Scope stdpp.
8+
Open Scope bv.
9+
10+
(** Extract R0 in a Z on success to have something printable by Coq *)
11+
Definition r0_extract (a : Model.Res.t ∅ 1) : result string Z :=
12+
match a with
13+
| Model.Res.FinalState fs =>
14+
let regs : registerMap := fs.(MState.regs) !!! 0%fin in
15+
if reg_lookup R0 regs is Some r0
16+
then Ok (bv_unsigned r0)
17+
else Error "R0 not in state"
18+
| Model.Res.Error s => Error s
19+
| Model.Res.Unspecified e => match e with end
20+
end.
21+
22+
Definition regs_extract (a : Model.Res.t ∅ 1) : result string (list (sigT reg_type)) :=
23+
match a with
24+
| Model.Res.FinalState fs =>
25+
let regs : registerMap := fs.(MState.regs) !!! 0%fin in
26+
Ok (dmap_to_list regs)
27+
| Model.Res.Error s => Error s
28+
| Model.Res.Unspecified e => match e with end
29+
end.
30+
31+
(** Common configuration from Isla config files to run at EL0 in AArch64 mode *)
32+
Definition common_init_regs :=
33+
isla_init_regs
34+
|> reg_insert PCUpdated false
35+
|> reg_insert EDESR 0x0
36+
|> reg_insert ShouldAdvanceIT false
37+
|> reg_insert ShouldAdvanceSS false
38+
|> reg_insert BTypeCompatible false
39+
|> reg_insert __InstructionStep false
40+
|> reg_insert SPESampleInFlight false
41+
|> reg_insert InGuardedPage false
42+
|> reg_insert __supported_pa_size 52%Z
43+
|> reg_insert __tlb_enabled false
44+
|> reg_insert __ExclusiveMonitorSet false
45+
|> reg_insert __ThisInstrEnc inhabitant
46+
|> reg_insert __ThisInstr 0x0
47+
|> reg_insert __currentCond 0x0
48+
|> reg_insert SEE 0x0%Z
49+
|> reg_insert BTypeNext 0x0
50+
51+
(* Registers that get read due to extra supported features, but which are irrelevant
52+
because the feature isn't used. *)
53+
|> reg_insert MAIR2_EL1 inhabitant
54+
|> reg_insert PIR_EL1 inhabitant
55+
|> reg_insert PIRE0_EL1 inhabitant
56+
|> reg_insert S2PIR_EL2 inhabitant
57+
.
58+
59+
60+
Module STRLDR. (* STR X2, [X1, X0]; LDR X0, [X1, X0] at 0x500, using address 0x1100 *)
61+
Definition init_reg : registerMap :=
62+
common_init_regs
63+
|> reg_insert PC 0x400000
64+
|> reg_insert R0 0x1000
65+
|> reg_insert R1 0x100
66+
|> reg_insert R2 0x2a.
67+
68+
Definition init_mem : memoryMap:=
69+
isla_init_mem
70+
|> mem_insert 0x1100 8 0x0. (* Memory need to exists to be written to *)
71+
72+
Definition termCond : terminationCondition 1 :=
73+
(λ tid rm, reg_lookup PC rm =? Some (0x400008 : bv 64)).
74+
75+
Definition initState :=
76+
{|MState.state :=
77+
{|MState.memory := init_mem;
78+
MState.regs := [# init_reg];
79+
MState.address_space := PAS_NonSecure |};
80+
MState.termCond := termCond |}.
81+
Definition test_results := sequential_modelc None 2 sail_arm_sem 1%nat initState.
82+
83+
Goal r0_extract <$> test_results = Listset [Ok 0x2a%Z].
84+
vm_compute (_ <$> _).
85+
reflexivity.
86+
Qed.
87+
End STRLDR.
88+

0 commit comments

Comments
 (0)