|
| 1 | +From ASCommon Require Import Options Common. |
| 2 | +From ArchSemArm Require Import ArmInst 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 | +(** We test against the sail-arm semantic, with non-determinism disabled *) |
| 60 | +Definition arm_sem := sail_arm_sem false. |
| 61 | + |
| 62 | +Module STRLDR. (* STR X2, [X1, X0]; LDR X0, [X1, X0] at 0x500, using address 0x1100 *) |
| 63 | + Definition init_reg : registerMap := |
| 64 | + common_init_regs |
| 65 | + |> reg_insert PC 0x400000 |
| 66 | + |> reg_insert R0 0x1000 |
| 67 | + |> reg_insert R1 0x100 |
| 68 | + |> reg_insert R2 0x2a. |
| 69 | + |
| 70 | + Definition init_mem : memoryMap:= |
| 71 | + isla_init_mem |
| 72 | + |> mem_insert 0x1100 8 0x0. (* Memory need to exists to be written to *) |
| 73 | + |
| 74 | + Definition termCond : terminationCondition 1 := |
| 75 | + (λ tid rm, reg_lookup PC rm =? Some (0x400008 : bv 64)). |
| 76 | + |
| 77 | + Definition initState := |
| 78 | + {|MState.state := |
| 79 | + {|MState.memory := init_mem; |
| 80 | + MState.regs := [# init_reg]; |
| 81 | + MState.address_space := PAS_NonSecure |}; |
| 82 | + MState.termCond := termCond |}. |
| 83 | + Definition test_results := sequential_modelc None 2 arm_sem 1%nat initState. |
| 84 | + |
| 85 | + Goal r0_extract <$> test_results = Listset [Ok 0x2a%Z]. |
| 86 | + vm_compute (_ <$> _). |
| 87 | + reflexivity. |
| 88 | + Qed. |
| 89 | +End STRLDR. |
| 90 | + |
0 commit comments