@@ -457,18 +457,16 @@ Definition read_mem4 (addr : address) (macc : mem_acc) (init : Memory.initial) :
457457 This may mutate memory if no existing promise can be fullfilled *)
458458Definition write_mem (tid : nat) (loc : Loc.t) (vdata : view)
459459 (macc : mem_acc) (mem : Memory.t)
460- (data : val) (mem_update : bool) :
460+ (data : val) :
461461 Exec.t TState.t string (Memory.t * view * option view):=
462462 let msg := Msg.make tid loc data in
463463 let is_release := is_rel_acq macc in
464464 ts ← mGet;
465- '(time, mem, new_promise) ←
465+ let '(time, mem, new_promise) :=
466466 match Memory.fulfill msg (TState.prom ts) mem with
467- | Some t => mret (t, mem, false)
468- | None =>
469- if mem_update then mret (Memory.promise msg mem, true)
470- else mdiscard
471- end ;
467+ | Some t => (t, mem, false)
468+ | None => (Memory.promise msg mem, true)
469+ end in
472470 let vbob :=
473471 ts.(TState.vdmbst) ⊔ ts.(TState.vdmb) ⊔ ts.(TState.visb) ⊔ ts.(TState.vacq)
474472 ⊔ view_if is_release (ts.(TState.vrd) ⊔ ts.(TState.vwr)) in
@@ -478,10 +476,8 @@ Definition write_mem (tid : nat) (loc : Loc.t) (vdata : view)
478476 mSet $ TState.update_coh loc time;;
479477 mSet $ TState.update TState.vwr time;;
480478 mSet $ TState.update TState.vrel (view_if is_release time);;
481- mret $ match new_promise with
482- | true => (mem, time, Some vpre)
483- | false => (mem, time, None)
484- end .
479+ mret (mem, time, (if new_promise then Some vpre else None)).
480+
485481
486482(** Tries to perform a memory write.
487483
@@ -492,12 +488,12 @@ Definition write_mem (tid : nat) (loc : Loc.t) (vdata : view)
492488 return value indicate the success (true for success, false for error) *)
493489Definition write_mem_xcl (tid : nat) (loc : Loc.t)
494490 (vdata : view) (macc : mem_acc)
495- (mem : Memory.t) (data : val) (mem_update : bool)
491+ (mem : Memory.t) (data : val)
496492 : Exec.t TState.t string (Memory.t * option view) :=
497493 guard_or "Atomic RMW unsupported" (¬ (is_atomic_rmw macc));;
498494 let xcl := is_exclusive macc in
499495 if xcl then
500- '(mem, time, vpre_opt) ← write_mem tid loc vdata macc mem data mem_update ;
496+ '(mem, time, vpre_opt) ← write_mem tid loc vdata macc mem data;
501497 ts ← mGet;
502498 match TState.xclb ts with
503499 | None => mdiscard
@@ -508,7 +504,7 @@ Definition write_mem_xcl (tid : nat) (loc : Loc.t)
508504 mSet TState.clear_xclb;;
509505 mret (mem, vpre_opt)
510506 else
511- '(mem, time, vpre_opt) ← write_mem tid loc vdata macc mem data mem_update ;
507+ '(mem, time, vpre_opt) ← write_mem tid loc vdata macc mem data;
512508 mSet $ TState.set_fwdb loc (FwdItem.make time vdata false);;
513509 mret (mem, vpre_opt).
514510
@@ -538,9 +534,9 @@ End IIS.
538534Section RunOutcome.
539535 Context (tid : nat) (initmem : memoryMap).
540536
541- Equations run_outcome (out : outcome) (mem_update : bool) :
537+ Equations run_outcome (out : outcome) :
542538 Exec.t (PPState.t TState.t Msg.t IIS.t) string (eff_ret out * option view) :=
543- | RegWrite reg racc val, mem_update =>
539+ | RegWrite reg racc val =>
544540 guard_or "Non trivial reg access types unsupported" (racc = None);;
545541 vreg ← mget (IIS.strict ∘ PPState.iis);
546542 vreg' ←
@@ -554,14 +550,14 @@ Section RunOutcome.
554550 TState.set_reg reg (val, vreg') ts;
555551 msetv PPState.state nts;;
556552 mret ((), None)
557- | RegRead reg racc, mem_update =>
553+ | RegRead reg racc =>
558554 guard_or "Non trivial reg access types unsupported" (racc = None);;
559555 ts ← mget PPState.state;
560556 '(val, view) ← othrow "Register isn't mapped can't read" $
561557 dmap_lookup reg ts.(TState.regs);
562558 mset PPState.iis $ IIS.add view;;
563559 mret (val, None)
564- | MemRead (MemReq.make macc addr addr_space 8 0), mem_update =>
560+ | MemRead (MemReq.make macc addr addr_space 8 0) =>
565561 guard_or "Access outside Non-Secure" (addr_space = PAS_NonSecure);;
566562 loc ← othrow "PA not supported" $ Loc.from_addr addr;
567563 if is_ifetch macc then
@@ -575,28 +571,28 @@ Section RunOutcome.
575571 mset PPState.iis $ IIS.add view;;
576572 mret (Ok (val, bv_0 0), None)
577573 else mthrow "Read is not explicit or ifetch"
578- | MemRead (MemReq.make macc addr addr_space 4 0), mem_update => (* ifetch *)
574+ | MemRead (MemReq.make macc addr addr_space 4 0) => (* ifetch *)
579575 guard_or "Access outside Non-Secure" (addr_space = PAS_NonSecure);;
580576 let initmem := Memory.initial_from_memMap initmem in
581577 opcode ← Exec.liftSt PPState.mem $ read_mem4 addr macc initmem;
582578 mret (Ok (opcode, 0%bv), None)
583- | MemRead _, mem_update => mthrow "Memory read of size other than 8 and 4"
584- | MemWriteAddrAnnounce _, mem_update =>
579+ | MemRead _ => mthrow "Memory read of size other than 8 and 4"
580+ | MemWriteAddrAnnounce _ =>
585581 vaddr ← mget (IIS.strict ∘ PPState.iis);
586582 mset PPState.state $ TState.update TState.vcap vaddr;;
587583 mret ((), None)
588- | MemWrite (MemReq.make macc addr addr_space 8 0) val tags, mem_update =>
584+ | MemWrite (MemReq.make macc addr addr_space 8 0) val tags =>
589585 guard_or "Access outside Non-Secure" (addr_space = PAS_NonSecure);;
590586 addr ← othrow "PA not supported" $ Loc.from_addr addr;
591587 if is_explicit macc then
592588 mem ← mget PPState.mem;
593589 vdata ← mget (IIS.strict ∘ PPState.iis);
594590 '(mem, vpre_opt) ← Exec.liftSt PPState.state
595- $ write_mem_xcl tid addr vdata macc mem val mem_update ;
591+ $ write_mem_xcl tid addr vdata macc mem val;
596592 msetv PPState.mem mem;;
597593 mret (Ok (), vpre_opt)
598594 else mthrow "Unsupported non-explicit write"
599- | Barrier (Barrier_DMB dmb), mem_update => (* dmb *)
595+ | Barrier (Barrier_DMB dmb) => (* dmb *)
600596 ts ← mget PPState.state;
601597 match dmb.(DxB_types) with
602598 | MBReqTypes_All (* dmb sy *) =>
@@ -607,16 +603,17 @@ Section RunOutcome.
607603 mset PPState.state $ TState.update TState.vdmbst ts.(TState.vwr)
608604 end ;;
609605 mret ((), None)
610- | Barrier (Barrier_ISB ()), mem_update => (* isb *)
606+ | Barrier (Barrier_ISB ()) => (* isb *)
611607 ts ← mget PPState.state;
612608 mset PPState.state $ TState.update TState.visb (TState.vcap ts);;
613609 mret ((), None)
614- | GenericFail s, mem_update => mthrow ("Instruction failure: " ++ s)%string
615- | _, _ => mthrow "Unsupported outcome".
610+ | GenericFail s => mthrow ("Instruction failure: " ++ s)%string
611+ | _ => mthrow "Unsupported outcome".
616612
617613 Definition run_outcome' (out : outcome) :
618614 Exec.t (PPState.t TState.t Msg.t IIS.t) string (eff_ret out) :=
619- run_outcome out true |$> fst.
615+ run_outcome out |$> fst.
616+
620617End RunOutcome.
621618
622619Module CProm.
@@ -655,14 +652,17 @@ Section ComputeProm.
655652 (base : view)
656653 (out : outcome) :
657654 Exec.t (CProm.t * PPState.t TState.t Msg.t IIS.t) string (eff_ret out) :=
658- '(res, vpre_opt) ← Exec.liftSt snd $ run_outcome tid initmem out true ;
655+ '(res, vpre_opt) ← Exec.liftSt snd $ run_outcome tid initmem out;
659656 if vpre_opt is Some vpre then
660657 mem ← mget (PPState.mem ∘ snd);
661658 mset fst (CProm.add_if mem vpre base);;
662659 mret res
663660 else
664661 mret res.
665662
663+ (* Run the thread state until termination, collecting certified promises.
664+ Returns true if termination occurs within the given fuel,
665+ false otherwise. *)
666666 Fixpoint run_to_termination_promise
667667 (isem : iMon ())
668668 (fuel : nat)
@@ -682,43 +682,7 @@ Section ComputeProm.
682682 run_to_termination_promise isem fuel base
683683 end .
684684
685- Definition run_to_termination (isem : iMon ())
686- (fuel : nat)
687- (ts : TState.t)
688- (mem : Memory.t) :
689- result string (list Msg.t * list TState.t) :=
690- let base := List.length mem in
691- let res := Exec.results $
692- run_to_termination_promise isem fuel base (CProm.init, PPState.Make ts mem IIS.init) in
693- guard_or ("Could not finish promises within the size of the fuel")%string
694- (∀ r ∈ res, r.2 = true);;
695- mret $ (CProm.proms (union_list res.*1.*1), []).
696-
697- Definition run_outcome_with_no_promise
698- (out : outcome) :
699- Exec.t (PPState.t TState.t Msg.t IIS.t) string (eff_ret out) :=
700- '(res, _) ← run_outcome tid initmem out false;
701- mret res.
702-
703- Fixpoint run_to_termination_no_promise
704- (isem : iMon ())
705- (fuel : nat) :
706- Exec.t (PPState.t TState.t Msg.t IIS.t) string bool :=
707- match fuel with
708- | 0%nat =>
709- ts ← mget PPState.state;
710- mret (term (TState.reg_map ts))
711- | S fuel =>
712- let handler := run_outcome_with_no_promise in
713- cinterp handler isem;;
714- ts ← mget PPState.state;
715- if term (TState.reg_map ts) then
716- mret true
717- else
718- run_to_termination_no_promise isem fuel
719- end .
720-
721- Definition run_to_termination_pf (isem : iMon ())
685+ Definition run_to_termination (isem : iMon ())
722686 (fuel : nat)
723687 (ts : TState.t)
724688 (mem : Memory.t)
@@ -729,11 +693,11 @@ Section ComputeProm.
729693 guard_or ("Could not finish promises within the size of the fuel")%string
730694 (∀ r ∈ res_proms, r.2 = true);;
731695 let promises := res_proms.*1.*1 |> CProm.proms ∘ union_list in
732- let res := Exec.results $
733- run_to_termination_no_promise isem fuel (PPState.Make ts mem IIS.init) in
734- guard_or ("Could not finish the remaining states within the size of the fuel")%string
735- (∀ r ∈ res, r.2 = true);;
736- let tstates := map PPState.state res.*1 in
696+ let tstates :=
697+ res_proms
698+ |> omap (λ '((cp, st), _),
699+ if is_emptyb (CProm.proms cp) then Some (PPState.state st)
700+ else None) in
737701 mret (promises, tstates).
738702
739703End ComputeProm.
@@ -819,20 +783,5 @@ Next Obligation. Admitted.
819783Next Obligation . Admitted .
820784Next Obligation . Admitted .
821785
822- Program Definition UMPromising_exe_pf' (isem : iMon ())
823- : BasicExecutablePM :=
824- {|pModel := UMPromising_cert' isem;
825- enumerate_promises_and_terminal_states :=
826- λ fuel tid term initmem ts mem,
827- run_to_termination_pf tid initmem term isem fuel ts mem
828- |}.
829- Next Obligation . Admitted .
830- Next Obligation . Admitted .
831- Next Obligation . Admitted .
832- Next Obligation . Admitted .
833-
834786Definition UMPromising_cert_c isem fuel :=
835787 Promising_to_Modelc isem (UMPromising_exe' isem) fuel.
836-
837- Definition UMPromising_cert_c_pf isem fuel :=
838- Promising_to_Modelc_pf isem (UMPromising_exe_pf' isem) fuel.
0 commit comments