-
Notifications
You must be signed in to change notification settings - Fork 0
/
Scheduler_IF.thy
2908 lines (2580 loc) · 128 KB
/
Scheduler_IF.thy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
(*
* Copyright 2020, Data61, CSIRO (ABN 41 687 119 230)
*
* SPDX-License-Identifier: GPL-2.0-only
*)
theory Scheduler_IF
imports "Syscall_IF" "PasUpdates"
begin
context begin interpretation Arch . (*FIXME: arch_splits*)
crunch cur_thread: activate_thread "\<lambda>s. P (cur_thread s)"
crunch cur_thread: arch_switch_to_thread "\<lambda>s. P( cur_thread s)"
(* After SELFOUR-553 scheduler no longer writes to shared memory *)
abbreviation scheduler_affects_globals_frame where
"scheduler_affects_globals_frame s \<equiv> {}"
definition globals_equiv_scheduler :: "'z::state_ext state \<Rightarrow> 'z::state_ext state \<Rightarrow> bool" where
"globals_equiv_scheduler s s' \<equiv> arm_global_pd (arch_state s) = arm_global_pd (arch_state s') \<and>
kheap s (arm_global_pd (arch_state s)) = kheap s' (arm_global_pd (arch_state s))
\<and> idle_equiv s s' \<and> device_region s = device_region s'"
definition scheduler_globals_frame_equiv :: "'z::state_ext state \<Rightarrow> 'z::state_ext state \<Rightarrow> bool" where
"scheduler_globals_frame_equiv s s' \<equiv> (\<forall>x\<in>scheduler_affects_globals_frame s. underlying_memory (machine_state s) x = underlying_memory (machine_state s') x
\<and> device_state (machine_state s) x = device_state (machine_state s') x)"
definition domain_fields_equiv :: "det_ext state \<Rightarrow> det_ext state \<Rightarrow> bool"
where
"domain_fields_equiv s s' \<equiv> cur_domain s = cur_domain s' \<and>
domain_time s = domain_time s' \<and>
domain_index s = domain_index s' \<and>
domain_list s = domain_list s'"
definition scheduler_equiv :: "'a subject_label PAS \<Rightarrow> det_ext state \<Rightarrow> det_ext state \<Rightarrow> bool"
where
"scheduler_equiv aag s s' \<equiv>
domain_fields_equiv s s' \<and> idle_thread s = idle_thread s' \<and> globals_equiv_scheduler s s' \<and> silc_dom_equiv aag s s' \<and> irq_state_of_state s = irq_state_of_state s'"
(* The equivalence relation for what the scheduler can affect.
Since information can flow from the scheduler to any domain,
we assert that the result states are equivalent with respect
to any domain.
*)
definition reads_scheduler where
"reads_scheduler aag l \<equiv> if (l = SilcLabel) then {} else
subjectReads (pasPolicy aag) l"
abbreviation reads_scheduler_cur_domain where
"reads_scheduler_cur_domain aag l s \<equiv>
pasDomainAbs aag (cur_domain s) \<inter> reads_scheduler aag l \<noteq> {}"
definition scheduler_affects_equiv :: "'a subject_label PAS \<Rightarrow> ('a subject_label) \<Rightarrow>
det_state \<Rightarrow> det_state \<Rightarrow> bool"
where
"scheduler_affects_equiv aag l s s' \<equiv>
(states_equiv_for_labels aag (\<lambda>l'. l' \<in> reads_scheduler aag l) s s' \<and>
(reads_scheduler_cur_domain aag l s \<or> reads_scheduler_cur_domain aag l s' \<longrightarrow>
(cur_thread s = cur_thread s' \<and> scheduler_action s = scheduler_action s' \<and>
work_units_completed s = work_units_completed s' \<and>
scheduler_globals_frame_equiv s s' \<and>
idle_thread s = idle_thread s' \<and>
(cur_thread s \<noteq> idle_thread s' \<longrightarrow> exclusive_state_equiv s s'))))"
lemma ev_modify:
"(\<And> s t. \<lbrakk>P s; P t; A s t; I s t\<rbrakk> \<Longrightarrow> (I (f s) (f t)) \<and> (B (f s) (f t)))
\<Longrightarrow> equiv_valid I A B P (modify f)"
apply (clarsimp simp add: equiv_valid_def2 equiv_valid_2_def simpler_modify_def)
done
abbreviation reads_respects_scheduler
where
"reads_respects_scheduler aag l P f \<equiv>
equiv_valid_inv (scheduler_equiv aag) (scheduler_affects_equiv aag l) P f"
lemma globals_equiv_from_scheduler:
"\<lbrakk> globals_equiv_scheduler s s'; scheduler_globals_frame_equiv s s'; cur_thread s = cur_thread s';
cur_thread s \<noteq> idle_thread s \<longrightarrow> exclusive_state_equiv s s'\<rbrakk> \<Longrightarrow>
globals_equiv s s'"
by (clarsimp simp: globals_equiv_scheduler_def scheduler_globals_frame_equiv_def
globals_equiv_def)
lemma globals_equiv_scheduler_refl:
"globals_equiv_scheduler s s"
by (simp add: globals_equiv_scheduler_def idle_equiv_refl)
lemma globals_equiv_scheduler_sym:
"globals_equiv_scheduler s s' \<Longrightarrow> globals_equiv_scheduler s' s"
by (auto simp add: globals_equiv_scheduler_def idle_equiv_sym)
lemma globals_equiv_scheduler_trans:
"globals_equiv_scheduler s s' \<Longrightarrow> globals_equiv_scheduler s' s'' \<Longrightarrow> globals_equiv_scheduler s s''"
apply (clarsimp simp add: globals_equiv_scheduler_def)
apply (rule idle_equiv_trans,assumption,assumption)
done
lemma scheduler_globals_frame_equiv_refl:
"scheduler_globals_frame_equiv s s"
by (simp add: scheduler_globals_frame_equiv_def)
lemma scheduler_globals_frame_equiv_sym[elim]:
"scheduler_globals_frame_equiv s s' \<Longrightarrow> scheduler_globals_frame_equiv s' s"
by (simp add: scheduler_globals_frame_equiv_def)
lemma scheduler_globals_frame_equiv_trans[elim]:
"scheduler_globals_frame_equiv s s' \<Longrightarrow> scheduler_globals_frame_equiv s' s''
\<Longrightarrow> scheduler_globals_frame_equiv s s''"
by (simp add: scheduler_globals_frame_equiv_def)
lemma preserves_equivalence_2_weak:
assumes A: "(u,b) \<in> fst (f s)"
assumes B: "(u',ba) \<in> fst (g t)"
assumes R_preserved: "\<And>st. \<lbrace>P and (R st)\<rbrace> f \<lbrace>\<lambda>_.(R st)\<rbrace>"
assumes R_preserved': "\<And>st. \<lbrace>S and (R st)\<rbrace> g \<lbrace>\<lambda>_.(R st)\<rbrace>"
assumes R_sym: "\<forall>s s'. R s s' \<longrightarrow> R s' s"
assumes R_trans: "\<forall>s s' s''. R s s' \<longrightarrow> R s' s'' \<longrightarrow> R s s''"
shows "\<lbrakk> R s t;P s; S t\<rbrakk> \<Longrightarrow> R b ba"
apply (insert A B)
apply (drule use_valid[OF _ R_preserved])
apply simp
apply (rule R_sym[rule_format])
apply assumption
apply (drule use_valid[OF _ R_preserved'])
apply simp
apply (metis R_trans R_sym)
done
lemma preserves_equivalence_weak:
assumes A: "(u,b) \<in> fst (f s)"
assumes B: "(u',ba) \<in> fst (f t)"
assumes R_preserved: "\<And>st. \<lbrace>P and (R st)\<rbrace> f \<lbrace>\<lambda>_.(R st)\<rbrace>"
assumes R_sym: "\<forall>s s'. R s s' \<longrightarrow> R s' s"
assumes R_trans: "\<forall>s s' s''. R s s' \<longrightarrow> R s' s'' \<longrightarrow> R s s''"
shows "\<lbrakk> R s t;P s; P t\<rbrakk> \<Longrightarrow> R b ba"
using assms
apply (blast intro: preserves_equivalence_2_weak)
done
lemma scheduler_equiv_trans[elim]:
"scheduler_equiv aag s s' \<Longrightarrow> scheduler_equiv aag s' s'' \<Longrightarrow> scheduler_equiv aag s s''"
apply (simp add: scheduler_equiv_def domain_fields_equiv_def)
apply clarify
apply (rule conjI)
apply (rule globals_equiv_scheduler_trans)
apply simp+
apply(blast intro: silc_dom_equiv_trans)
done
lemma scheduler_equiv_sym[elim]:
"scheduler_equiv aag s s' \<Longrightarrow> scheduler_equiv aag s' s"
by (simp add: scheduler_equiv_def domain_fields_equiv_def globals_equiv_scheduler_sym
silc_dom_equiv_sym)
lemma scheduler_affects_equiv_trans[elim]:
"\<lbrakk>scheduler_affects_equiv aag l s s'; scheduler_equiv aag s s';
scheduler_affects_equiv aag l s' s''; scheduler_equiv aag s' s''\<rbrakk>
\<Longrightarrow> scheduler_affects_equiv aag l s s''"
apply (simp add: scheduler_affects_equiv_def scheduler_equiv_trans[where s'=s'])+
apply clarify
apply (rule conjI)
apply (rule states_equiv_for_trans[where t=s'])
apply simp+
apply (force simp: scheduler_globals_frame_equiv_trans[where s'=s'] scheduler_equiv_def
domain_fields_equiv_def)
done
lemma scheduler_affects_equiv_sym[elim]:
"scheduler_affects_equiv aag l s s' \<Longrightarrow> scheduler_affects_equiv aag l s' s"
apply (simp add: scheduler_affects_equiv_def)
(* faster than the one-liner *)
apply (clarsimp simp: scheduler_globals_frame_equiv_sym states_equiv_for_sym silc_dom_equiv_sym)
apply force
done
declare globals_equiv_scheduler_sym[elim]
declare globals_equiv_scheduler_trans[elim]
declare silc_dom_equiv_sym[elim]
declare silc_dom_equiv_trans[elim]
lemma scheduler_equiv_lift':
assumes s: "\<And>st. \<lbrace>P and globals_equiv_scheduler st\<rbrace> f \<lbrace>\<lambda>_.(globals_equiv_scheduler st)\<rbrace>"
assumes d: "\<And>Q. \<lbrace>P and (\<lambda>s. Q (cur_domain s))\<rbrace> f \<lbrace>\<lambda>r s. Q (cur_domain s)\<rbrace>"
assumes i: "\<And>P. invariant f (\<lambda>s. P (idle_thread s))"
assumes e: "\<And>Q. \<lbrace>P and domain_fields Q\<rbrace> f \<lbrace>\<lambda>_. domain_fields Q\<rbrace>"
assumes g: "\<And>P. invariant f (\<lambda>s. P (irq_state_of_state s))"
assumes f: "\<And>st. \<lbrace>P and silc_dom_equiv aag st\<rbrace> f \<lbrace>\<lambda>_. silc_dom_equiv aag st\<rbrace>"
shows "\<lbrace>P and scheduler_equiv aag st\<rbrace> f \<lbrace>\<lambda>_. scheduler_equiv aag st\<rbrace>"
apply (simp add: scheduler_equiv_def[abs_def] domain_fields_equiv_def)
apply (rule hoare_pre)
apply (wp d e s i f g)
apply simp
done
lemmas scheduler_equiv_lift = scheduler_equiv_lift'[where P=\<top>,simplified]
lemma equiv_valid_inv_unobservable:
assumes f: "\<And>st. \<lbrace>P and I st and A st\<rbrace> f \<lbrace>\<lambda>_. I st\<rbrace>"
assumes g: "\<And>st. \<lbrace>P' and I st and A st\<rbrace> f \<lbrace>\<lambda>_. A st\<rbrace>"
assumes sym: "\<forall>s s'. I s s' \<and> A s s' \<longrightarrow> I s' s \<and> A s' s"
assumes trans: "\<forall>s s' s''. I s s' \<and> A s s' \<longrightarrow> I s' s'' \<and> A s' s'' \<longrightarrow> I s s'' \<and> A s s''"
assumes s: "\<And>s. Q s \<Longrightarrow> P s \<and> P' s"
shows "equiv_valid_inv I A Q (f:: 'a \<Rightarrow> (unit \<times> 'a) set \<times> bool)"
apply (clarsimp simp add: equiv_valid_def spec_equiv_valid_def equiv_valid_2_def)
apply (erule preserves_equivalence_weak,assumption)
apply (rule hoare_pre)
apply (rule hoare_vcg_conj_lift)
apply (rule f)
apply (rule g)
apply force
apply (insert s)
apply (fastforce intro!: sym trans)+
done
lemma reads_respects_scheduler_unobservable'':
"\<lbrakk>\<And>st. \<lbrace>P and scheduler_equiv aag st and scheduler_affects_equiv aag l st\<rbrace> f
\<lbrace>\<lambda>_. scheduler_equiv aag st\<rbrace>;
\<And>st. \<lbrace>P' and scheduler_equiv aag st and scheduler_affects_equiv aag l st\<rbrace> f
\<lbrace>\<lambda>(_ :: unit). scheduler_affects_equiv aag l st\<rbrace>;
\<And>s. Q s \<Longrightarrow> P s \<and> P' s\<rbrakk>
\<Longrightarrow> reads_respects_scheduler aag l Q f"
apply (rule equiv_valid_inv_unobservable,fastforce+)
done
lemma reads_respects_scheduler_unobservable':
assumes f: "\<And>st. \<lbrace>P and scheduler_equiv aag st\<rbrace> f \<lbrace>\<lambda>_. scheduler_equiv aag st\<rbrace>"
assumes g:
"\<And>st. \<lbrace>P and scheduler_affects_equiv aag l st\<rbrace> f \<lbrace>\<lambda>_. scheduler_affects_equiv aag l st\<rbrace>"
shows "reads_respects_scheduler aag l P (f:: (unit,det_ext) s_monad)"
apply (rule reads_respects_scheduler_unobservable'')
apply (wp f g | force)+
done
definition swap_things where
"swap_things s t \<equiv> t\<lparr> machine_state := underlying_memory_update
(\<lambda>m a. if a \<in> scheduler_affects_globals_frame t
then (underlying_memory (machine_state s) a)
else m a) (machine_state t)
\<lparr>exclusive_state := exclusive_state (machine_state s)\<rparr>\<rparr>
\<lparr>cur_thread := cur_thread s\<rparr>"
lemma idle_equiv_machine_state_update[simp]:
"idle_equiv st (s\<lparr>machine_state := x\<rparr>) = idle_equiv st s"
by (simp add: idle_equiv_def)
lemma idle_equiv_machine_state_update'[simp]:
"idle_equiv (st\<lparr>machine_state := x\<rparr>) s = idle_equiv st s"
by (simp add: idle_equiv_def)
lemma idle_equiv_cur_thread_update'[simp]:
"idle_equiv (st\<lparr>cur_thread := x\<rparr>) s = idle_equiv st s"
by (simp add: idle_equiv_def)
lemma globals_equiv_scheduler_inv':
"\<lbrakk>(\<And>st. \<lbrace> P and globals_equiv st\<rbrace> f \<lbrace>\<lambda>_. globals_equiv st\<rbrace>)\<rbrakk> \<Longrightarrow>
\<lbrace> P and globals_equiv_scheduler s\<rbrace> f \<lbrace>\<lambda>_. globals_equiv_scheduler s\<rbrace>"
apply atomize
apply (rule use_spec)
apply (simp add: spec_valid_def)
apply (erule_tac x="(swap_things sa s)" in allE)
apply (rule_tac Q="\<lambda>r st. globals_equiv (swap_things sa s) st" in hoare_strengthen_post )
apply (rule hoare_pre)
apply assumption
apply (clarsimp simp add: globals_equiv_def swap_things_def globals_equiv_scheduler_def)+
done
lemmas globals_equiv_scheduler_inv = globals_equiv_scheduler_inv'[where P="\<top>",simplified]
lemmas reads_respects_scheduler_unobservable =
reads_respects_scheduler_unobservable'[where P="\<top>",simplified]
lemma silc_dom_equiv_scheduler_action_update[simp]:
"silc_dom_equiv aag st (s\<lparr>scheduler_action := x\<rparr>) = silc_dom_equiv aag st s"
by (simp add: silc_dom_equiv_def equiv_for_def)
crunch silc_dom_equiv[wp]: set_scheduler_action "silc_dom_equiv aag st"
(ignore_del: set_scheduler_action)
lemma schedule_globals_frame_trans_state_upd[simp]:
"scheduler_globals_frame_equiv st (trans_state f s) = scheduler_globals_frame_equiv st s"
by (simp add: scheduler_globals_frame_equiv_def)
lemma idle_equiv_scheduler_action_update[simp]:
"idle_equiv (scheduler_action_update f st) s = idle_equiv st s"
by (simp add: idle_equiv_def)
lemma idle_equiv_scheduler_action_update'[simp]:
"idle_equiv st (scheduler_action_update f s) = idle_equiv st s"
by (simp add: idle_equiv_def)
lemma set_scheduler_action_rev_scheduler[wp]:
"reads_respects_scheduler aag l \<top> (set_scheduler_action a)"
apply (clarsimp simp add: set_scheduler_action_def)
apply (rule ev_modify)
apply (clarsimp simp add: scheduler_affects_equiv_def
scheduler_equiv_def states_equiv_for_def
equiv_asids_def equiv_asid_def
domain_fields_equiv_def
globals_equiv_scheduler_def
silc_dom_equiv_def
scheduler_globals_frame_equiv_def
equiv_for_def)
done
lemma globals_equiv_scheduler_cur_thread_update[simp]:
"globals_equiv_scheduler st (s\<lparr>cur_thread := x\<rparr>) = globals_equiv_scheduler st s"
by (simp add: globals_equiv_scheduler_def idle_equiv_def)
lemma globals_equiv_scheduler_trans_state_update[simp]:
"globals_equiv_scheduler st (trans_state f s) = globals_equiv_scheduler st s"
by (simp add: globals_equiv_scheduler_def idle_equiv_def)
lemma states_equiv_for_cur_thread_update[simp]:
"states_equiv_for P Q R S s (s'\<lparr>cur_thread := x\<rparr>) = states_equiv_for P Q R S s s'"
by (simp add: states_equiv_for_def equiv_for_def equiv_asids_def equiv_asid_def)
lemma scheduler_globals_frame_equiv_cur_thread_update[simp]:
"scheduler_globals_frame_equiv st (s\<lparr>cur_thread := x\<rparr>) = scheduler_globals_frame_equiv st s"
by (simp add: scheduler_globals_frame_equiv_def)
lemma scheduler_globals_frame_equiv_ready_queues_update[simp]:
"scheduler_globals_frame_equiv st (s\<lparr>ready_queues := x\<rparr>) = scheduler_globals_frame_equiv st s"
by (simp add: scheduler_globals_frame_equiv_def)
lemma scheduler_globals_frame_equiv_ready_queues_update'[simp]:
"scheduler_globals_frame_equiv (st\<lparr>ready_queues := x\<rparr>) s = scheduler_globals_frame_equiv st s"
by (simp add: scheduler_globals_frame_equiv_def)
lemma silc_dom_equiv_cur_thread_update[simp]:
"silc_dom_equiv aag st (s\<lparr>cur_thread := x\<rparr>) = silc_dom_equiv aag st s"
by (simp add: silc_dom_equiv_def equiv_for_def)
lemma silc_dom_equiv_ready_queues_update[simp]:
"silc_dom_equiv aag st (s\<lparr>ready_queues := x\<rparr>) = silc_dom_equiv aag st s"
by (simp add: silc_dom_equiv_def equiv_for_def)
lemma silc_dom_equiv_ready_queues_update'[simp]:
"silc_dom_equiv aag (st\<lparr>ready_queues := x\<rparr>) s = silc_dom_equiv aag st s"
by (simp add: silc_dom_equiv_def equiv_for_def)
lemma silc_dom_equiv_cur_thread_update'[simp]:
"silc_dom_equiv aag (st\<lparr>cur_thread := x\<rparr>) s = silc_dom_equiv aag st s"
by (simp add: silc_dom_equiv_def equiv_for_def)
lemma scheduler_equiv_ready_queues_update[simp]:
"scheduler_equiv aag (st\<lparr>ready_queues := x\<rparr>) s = scheduler_equiv aag st s"
by (simp add: scheduler_equiv_def domain_fields_equiv_def globals_equiv_scheduler_def
idle_equiv_def)
lemma scheduler_equiv_ready_queues_update'[simp]:
"scheduler_equiv aag st (s\<lparr>ready_queues := x\<rparr>) = scheduler_equiv aag st s"
by (simp add: scheduler_equiv_def domain_fields_equiv_def globals_equiv_scheduler_def
idle_equiv_def)
lemma get_tcb_queue_reads_respects_scheduler[wp]:
"reads_respects_scheduler aag l (K(pasDomainAbs aag rv \<inter> reads_scheduler aag l \<noteq> {}))
(get_tcb_queue rv rva)"
apply (rule gen_asm_ev)
apply (simp add: get_tcb_queue_def)
apply (subst gets_apply)
apply (wp gets_apply_ev)
apply (force simp: scheduler_affects_equiv_def states_equiv_for_def
equiv_for_def disjoint_iff_not_equal)
done
lemma ethread_get_reads_respects_scheduler[wp]:
"reads_respects_scheduler aag l (K(pasObjectAbs aag t \<in> reads_scheduler aag l)) (ethread_get f t)"
apply (rule gen_asm_ev)
apply (simp add: ethread_get_def)
apply wp
apply (clarsimp simp add: scheduler_affects_equiv_def states_equiv_for_def
equiv_for_def get_etcb_def)
done
lemma ethread_get_when_reads_respects_scheduler[wp]:
"reads_respects_scheduler aag l (K(b \<longrightarrow> pasObjectAbs aag t \<in> reads_scheduler aag l))
(ethread_get_when b f t)"
apply (simp add: ethread_get_when_def)
apply (rule conjI; clarsimp)
using ethread_get_reads_respects_scheduler
apply fastforce
apply wp
done
end
lemma (in is_extended') globals_equiv[wp]:
"I (globals_equiv st)"
by (rule lift_inv,simp)
lemma (in is_extended') globals_equiv_scheduler[wp]:
"I (globals_equiv_scheduler st)"
by (rule lift_inv,simp)
context begin interpretation Arch . (*FIXME: arch_split*)
lemma tcb_domain_wellformed:
"\<lbrakk>pas_refined aag s; ekheap s t = Some a\<rbrakk> \<Longrightarrow> pasObjectAbs aag t \<in> pasDomainAbs aag (tcb_domain a)"
apply (clarsimp simp add: pas_refined_def tcb_domain_map_wellformed_aux_def)
apply (drule_tac x="(t,tcb_domain a)" in bspec)
apply (rule domtcbs)
apply force+
done
lemma reads_respects_scheduler_cases:
assumes b:
"pasObjectAbs aag t \<in> reads_scheduler aag l \<Longrightarrow> reads_respects_scheduler aag l P' (f t)"
assumes b': "\<And>s. Q s \<Longrightarrow> pasObjectAbs aag t \<in> reads_scheduler aag l \<Longrightarrow> P' s"
assumes c:
"pasObjectAbs aag t \<notin> reads_scheduler aag l \<Longrightarrow> reads_respects_scheduler aag l P'' (f t)"
assumes c': "\<And>s. Q s \<Longrightarrow> pasObjectAbs aag t \<notin> reads_scheduler aag l \<Longrightarrow> P'' s"
shows "reads_respects_scheduler aag l Q (f t)"
apply (insert b b' c c')
apply (case_tac "pasObjectAbs aag t \<in> reads_scheduler aag l")
apply (fastforce intro: equiv_valid_guard_imp)+
done
lemma silc_dom_equiv_trans_state[simp]:
"silc_dom_equiv aag st (trans_state f s) = silc_dom_equiv aag st s"
by (simp add: silc_dom_equiv_def equiv_for_def)
end
lemma (in is_extended') silc_dom_equiv[wp]:
"I (silc_dom_equiv aag st)"
by (rule lift_inv,simp)
context begin interpretation Arch . (*FIXME: arch_split*)
lemma tcb_action_reads_respects_scheduler[wp]:
assumes domains_distinct: "pas_domains_distinct aag"
shows
"reads_respects_scheduler aag l (pas_refined aag) (tcb_sched_action f t)"
apply (rule reads_respects_scheduler_cases)
apply (simp add: tcb_sched_action_def set_tcb_queue_def)
apply wp
apply (rule ev_modify[where P=\<top>])
apply (clarsimp simp add: scheduler_equiv_def domain_fields_equiv_def
globals_equiv_scheduler_def)
apply (clarsimp simp: scheduler_affects_equiv_def states_equiv_for_def
equiv_for_def equiv_asids_def equiv_asid_def idle_equiv_def
)
apply metis
apply wp+
apply (clarsimp simp add: etcb_at_def split: option.splits)
apply (frule(1) tcb_domain_wellformed)
apply blast
apply (simp add: tcb_sched_action_def set_tcb_queue_def)
apply (rule reads_respects_scheduler_unobservable'[where P="pas_refined aag"])
apply wp
apply (clarsimp simp add: etcb_at_def split: option.splits)
apply wp
apply (clarsimp simp: etcb_at_def split: option.splits)
apply (clarsimp simp: scheduler_affects_equiv_def states_equiv_for_def
equiv_for_def equiv_asids_def equiv_asid_def)
apply (frule(1) tcb_domain_wellformed)
apply (rule ext)
apply (solves \<open>auto dest: domains_distinct[THEN pas_domains_distinct_inj]\<close>)
apply assumption
done
lemma dmo_no_mem_globals_equiv_scheduler:
assumes a: "(\<And>P. invariant f (\<lambda>ms. P (underlying_memory ms)))"
and b: "(\<And>P. invariant f (\<lambda>ms. P (device_state ms)))"
shows "invariant (do_machine_op f) (globals_equiv_scheduler s)"
unfolding do_machine_op_def
apply (rule hoare_pre)
apply (wp | simp add: split_def)+
apply clarsimp
apply (frule_tac P1 = "\<lambda>um. um = underlying_memory (machine_state sa)" in use_valid[OF _ a])
apply simp
apply (frule_tac P1 = "\<lambda>um. um = device_state (machine_state sa)" in use_valid[OF _ b])
apply simp
apply (fastforce simp: valid_def globals_equiv_scheduler_def idle_equiv_def)
done
lemma clearExMonitor_globals_equiv_scheduler[wp]:
"\<lbrace> globals_equiv_scheduler sta \<rbrace> do_machine_op clearExMonitor \<lbrace> \<lambda>_. globals_equiv_scheduler sta \<rbrace>"
unfolding clearExMonitor_def including no_pre
apply (wp dmo_no_mem_globals_equiv_scheduler)
apply simp
apply (simp add: simpler_modify_def valid_def)
done
lemma arch_switch_to_thread_globals_equiv_scheduler:
"\<lbrace>invs and globals_equiv_scheduler sta\<rbrace> arch_switch_to_thread thread
\<lbrace>\<lambda>_. globals_equiv_scheduler sta\<rbrace>"
unfolding arch_switch_to_thread_def storeWord_def
by (wpsimp wp: clearExMonitor_globals_equiv_scheduler dmo_wp modify_wp thread_get_wp'
| wp (once) globals_equiv_scheduler_inv'[where P="\<top>"])+
lemma dmo_storeWord_reads_respects_scheduler[wp]:
"reads_respects_scheduler aag l \<top> (do_machine_op (storeWord rva rvb))"
apply (clarsimp simp add: do_machine_op_def bind_def gets_def get_def
return_def select_f_def storeWord_def
assert_def simpler_modify_def fail_def)
apply (fold simpler_modify_def)
apply (intro impI conjI)
apply (rule ev_modify)
apply (clarsimp simp: scheduler_equiv_def domain_fields_equiv_def
globals_equiv_scheduler_def)
apply (clarsimp simp add: scheduler_affects_equiv_def states_equiv_for_def
equiv_for_def equiv_asids_def equiv_asid_def
scheduler_globals_frame_equiv_def silc_dom_equiv_def
)
apply (simp add: equiv_valid_def2 equiv_valid_2_def)
done
definition weak_scheduler_affects_equiv :: "'a subject_label PAS \<Rightarrow> ('a subject_label) \<Rightarrow>
det_state \<Rightarrow> det_state \<Rightarrow> bool"
where
"weak_scheduler_affects_equiv aag l s s' \<equiv>
(states_equiv_for_labels aag (\<lambda>l'. l' \<in> reads_scheduler aag l) s s')"
definition midstrength_scheduler_affects_equiv :: "'a subject_label PAS \<Rightarrow> ('a subject_label) \<Rightarrow>
det_state \<Rightarrow> det_state \<Rightarrow> bool"
where
"midstrength_scheduler_affects_equiv aag l s s' \<equiv>
(states_equiv_for_labels aag (\<lambda>l'. l' \<in> reads_scheduler aag l) s s') \<and>
(reads_scheduler_cur_domain aag l s \<or> reads_scheduler_cur_domain aag l s' \<longrightarrow>
work_units_completed s = work_units_completed s')"
abbreviation strong_reads_respects_scheduler
where
"strong_reads_respects_scheduler aag l P f \<equiv>
equiv_valid (scheduler_equiv aag) (weak_scheduler_affects_equiv aag l)
(scheduler_affects_equiv aag l) P f"
abbreviation midstrength_reads_respects_scheduler
where
"midstrength_reads_respects_scheduler aag l P f \<equiv>
equiv_valid (scheduler_equiv aag) (midstrength_scheduler_affects_equiv aag l)
(scheduler_affects_equiv aag l) P f"
abbreviation weak_reads_respects_scheduler
where
"weak_reads_respects_scheduler aag l P f \<equiv>
equiv_valid (scheduler_equiv aag) (weak_scheduler_affects_equiv aag l)
(weak_scheduler_affects_equiv aag l) P f"
lemma store_cur_thread_midstrength_reads_respects:
"equiv_valid (scheduler_equiv aag) (midstrength_scheduler_affects_equiv aag l)
(scheduler_affects_equiv aag l) (invs and (\<lambda>s. t = idle_thread s))
(do x \<leftarrow> modify (cur_thread_update (\<lambda>_. t));
set_scheduler_action resume_cur_thread
od)"
apply (clarsimp simp add: do_machine_op_def bind_def gets_def get_def
return_def select_f_def storeWord_def bind_def
set_scheduler_action_def
assert_def simpler_modify_def fail_def)
apply (fold simpler_modify_def)
apply (rule ev_modify)
apply (clarsimp simp: scheduler_equiv_def domain_fields_equiv_def
globals_equiv_scheduler_def)
apply (clarsimp simp: scheduler_affects_equiv_def states_equiv_for_def
equiv_for_def equiv_asids_def equiv_asid_def
scheduler_globals_frame_equiv_def silc_dom_equiv_def
weak_scheduler_affects_equiv_def midstrength_scheduler_affects_equiv_def
idle_equiv_def)
done
lemma globals_frame_equiv_as_states_equiv:
"scheduler_globals_frame_equiv st s =
states_equiv_for
(\<lambda>x. x \<in> scheduler_affects_globals_frame s) \<bottom> \<bottom> \<bottom>
(s\<lparr>machine_state := machine_state st, arch_state := arch_state st\<rparr>) s"
by (clarsimp simp add: states_equiv_for_def equiv_for_def
scheduler_globals_frame_equiv_def
equiv_asids_def)
lemma silc_dom_equiv_as_states_equiv:
"silc_dom_equiv aag st s =
states_equiv_for
(\<lambda>x. pasObjectAbs aag x = SilcLabel) \<bottom> \<bottom> \<bottom>
(s\<lparr>kheap := kheap st\<rparr>) s"
apply (clarsimp simp add: states_equiv_for_def equiv_for_def
silc_dom_equiv_def
equiv_asids_def)
done
lemma silc_dom_equiv_states_equiv_lift:
assumes a: "\<And>P Q R S st. \<lbrace>states_equiv_for P Q R S st\<rbrace> f \<lbrace>\<lambda>_. states_equiv_for P Q R S st\<rbrace>"
shows "\<lbrace>silc_dom_equiv aag st\<rbrace> f \<lbrace>\<lambda>_. silc_dom_equiv aag st\<rbrace>"
apply (simp add: silc_dom_equiv_as_states_equiv[abs_def])
apply (clarsimp simp add: valid_def)
apply (frule use_valid[OF _ a])
apply assumption
apply (simp add: states_equiv_for_def equiv_for_def equiv_asids_def)
done
lemma scheduler_affects_equiv_unobservable:
assumes a: "\<And>P Q R S st. \<lbrace>states_equiv_for P Q R S st\<rbrace> f \<lbrace>\<lambda>_. states_equiv_for P Q R S st\<rbrace>"
assumes c: "\<And>P. \<lbrace>\<lambda>s. P (cur_domain s)\<rbrace> f \<lbrace>\<lambda>r s. P (cur_domain s)\<rbrace>"
assumes e: "\<And>P. \<lbrace>\<lambda>s. P (cur_thread s)\<rbrace> f \<lbrace>\<lambda>r s. P (cur_thread s)\<rbrace>"
assumes s: "\<And>P. \<lbrace>\<lambda>s. P (scheduler_action s)\<rbrace> f \<lbrace>\<lambda>r s. P (scheduler_action s)\<rbrace>"
assumes w: "\<And>P. \<lbrace>\<lambda>s. P (work_units_completed s)\<rbrace> f \<lbrace>\<lambda>r s. P (work_units_completed s)\<rbrace>"
assumes i: "\<And>P. \<lbrace>\<lambda>s. P (idle_thread s)\<rbrace> f \<lbrace>\<lambda>r s. P (idle_thread s)\<rbrace>"
assumes x:
"\<And>P. \<lbrace>\<lambda>s. P (exclusive_state (machine_state s))\<rbrace>
f
\<lbrace>\<lambda>r s. P (exclusive_state (machine_state s))\<rbrace>"
shows "\<lbrace>scheduler_affects_equiv aag l st\<rbrace>
f
\<lbrace>\<lambda>_. scheduler_affects_equiv aag l st\<rbrace>"
proof -
have d: "\<lbrace>scheduler_globals_frame_equiv st\<rbrace> f \<lbrace>\<lambda>_. scheduler_globals_frame_equiv st\<rbrace>"
apply (simp add: globals_frame_equiv_as_states_equiv[abs_def])
apply (clarsimp simp add: valid_def)
apply (frule use_valid[OF _ a])
apply assumption
apply (simp add: states_equiv_for_def equiv_for_def equiv_asids_def)
done
show ?thesis
apply (simp add: scheduler_affects_equiv_def[abs_def])
apply (rule hoare_pre)
apply (wps c)
apply (wp static_imp_wp a silc_dom_equiv_states_equiv_lift d e s w i x hoare_vcg_imp_lift)
apply fastforce
done
qed
lemma midstrength_scheduler_affects_equiv_unobservable:
assumes a: "\<And>P Q R S st. \<lbrace>states_equiv_for P Q R S st\<rbrace> f \<lbrace>\<lambda>_. states_equiv_for P Q R S st\<rbrace>"
assumes w:
"\<And>P. \<lbrace>\<lambda>s. P (cur_domain s) (work_units_completed s)\<rbrace>
f
\<lbrace>\<lambda>r s. P (cur_domain s) (work_units_completed s)\<rbrace>"
shows "\<lbrace>midstrength_scheduler_affects_equiv aag l st\<rbrace>
f
\<lbrace>\<lambda>_. midstrength_scheduler_affects_equiv aag l st\<rbrace>"
apply (simp add: midstrength_scheduler_affects_equiv_def[abs_def])
apply (rule hoare_pre)
apply (wp a w silc_dom_equiv_states_equiv_lift)
apply clarsimp
done
lemma dmo_mol_exclusive_state[wp]:
"invariant (do_machine_op (machine_op_lift mop)) (\<lambda>s. P (exclusive_state (machine_state s)))"
by(wp mol_exclusive_state dmo_wp
| simp add: split_def dmo_bind_valid writeTTBR0_def isb_def dsb_def )+
crunch exclusive_state[wp]: set_vm_root "\<lambda>s. P (exclusive_state (machine_state s))"
(ignore: do_machine_op
simp: invalidateLocalTLB_ASID_def setHardwareASID_def set_current_pd_def dsb_def isb_def
writeTTBR0_def dmo_bind_valid crunch_simps)
lemmas set_vm_root_scheduler_affects_equiv[wp] =
scheduler_affects_equiv_unobservable[OF set_vm_root_states_equiv_for
set_vm_root_exst _ _ _ set_vm_root_it
set_vm_root_exclusive_state]
lemma set_vm_root_reads_respects_scheduler[wp]:
"reads_respects_scheduler aag l \<top> (set_vm_root thread)"
apply (rule reads_respects_scheduler_unobservable'[
OF scheduler_equiv_lift'[OF globals_equiv_scheduler_inv']])
apply (wp silc_dom_equiv_states_equiv_lift set_vm_root_states_equiv_for | simp)+
done
lemma thread_get_reads_respects_scheduler[wp]:
"reads_respects_scheduler aag l (K(pasObjectAbs aag t \<in> reads_scheduler aag l)) (thread_get f t)"
apply (rule gen_asm_ev)
apply (simp add: thread_get_def)
apply wp
apply (clarsimp simp add: scheduler_affects_equiv_def states_equiv_for_def
equiv_for_def get_tcb_def)
done
crunch idle_thread[wp]: guarded_switch_to,schedule "\<lambda>(s :: det_state). P (idle_thread s)"
(wp: crunch_wps simp: crunch_simps)
lemma silc_dom_lift:
assumes a: "\<And>P. \<lbrace>\<lambda>s. P (kheap s)\<rbrace> f \<lbrace>\<lambda>r s. P (kheap s)\<rbrace>"
shows "\<lbrace>silc_dom_equiv aag st\<rbrace> f \<lbrace>\<lambda>_. silc_dom_equiv aag st\<rbrace>"
apply (simp add: silc_dom_equiv_def equiv_for_def[abs_def])
apply (wp a)
done
lemma dmo_silc_dom[wp]:
"\<lbrace>silc_dom_equiv aag st\<rbrace> do_machine_op mop \<lbrace>\<lambda>_. silc_dom_equiv aag st\<rbrace>"
by (wp silc_dom_lift)
crunch kheap[wp]: guarded_switch_to, schedule "\<lambda>s :: det_state. P (kheap s)"
(wp: dxo_wp_weak crunch_wps simp: crunch_simps)
lemma storeWord_irq_state_of_state[wp]:
"\<lbrace>\<lambda>s. P (irq_state_of_state s)\<rbrace> do_machine_op (storeWord x y) \<lbrace>\<lambda>_ s. P (irq_state_of_state s)\<rbrace>"
apply (simp add: storeWord_def)
apply (wp dmo_wp modify_wp)
apply simp
done
lemma clearExMonitor_irq_state_of_state[wp]:
"\<lbrace>\<lambda>s. P (irq_state_of_state s)\<rbrace> do_machine_op clearExMonitor \<lbrace>\<lambda>_ s. P (irq_state_of_state s)\<rbrace>"
by (wpsimp wp: dmo_wp irq_state_clearExMonitor)
lemma clearExMonitor_scheduler_equiv[wp]:
"\<lbrace> scheduler_equiv aag st \<rbrace> do_machine_op clearExMonitor \<lbrace> \<lambda>_. scheduler_equiv aag st \<rbrace>"
by (rule scheduler_equiv_lift; wp)
lemma dmo_ev:
"(\<And>s s'. equiv_valid (\<lambda>ms ms'. I (s\<lparr>machine_state := ms\<rparr>) (s'\<lparr>machine_state := ms'\<rparr>))
(\<lambda>ms ms'. A (s\<lparr>machine_state := ms\<rparr>) (s'\<lparr>machine_state := ms'\<rparr>))
(\<lambda>ms ms'. B (s\<lparr>machine_state := ms\<rparr>) (s'\<lparr>machine_state := ms'\<rparr>))
(K (P s \<and> P s')) f)
\<Longrightarrow> equiv_valid I A B P (do_machine_op f)"
apply (clarsimp simp: do_machine_op_def bind_def equiv_valid_def2 equiv_valid_2_def gets_def
get_def select_f_def modify_def put_def return_def split_def)
apply atomize
apply (erule_tac x=s in allE)
apply (erule_tac x=t in allE)
apply simp
apply (erule_tac x="machine_state s" in allE)
apply (erule_tac x="machine_state t" in allE)
apply fastforce
done
lemma [wp]: "reads_respects_scheduler aag l (\<lambda>_. True) (do_machine_op clearExMonitor)"
apply (simp add: clearExMonitor_def)
apply (wp dmo_ev)
apply (rule ev_modify)
apply clarsimp
apply (rule conjI)
apply (clarsimp simp: scheduler_equiv_def domain_fields_equiv_def globals_equiv_scheduler_def
silc_dom_equiv_def equiv_for_def)
apply (clarsimp simp: scheduler_affects_equiv_def states_equiv_for_def equiv_for_def
equiv_asids_def equiv_asid_def scheduler_globals_frame_equiv_def
simp del: split_paired_All)
done
definition asahi_scheduler_affects_equiv ::
"'a subject_label PAS \<Rightarrow> 'a subject_label \<Rightarrow> det_ext state \<Rightarrow> det_ext state \<Rightarrow> bool"
where
"asahi_scheduler_affects_equiv aag l s s' \<equiv>
states_equiv_for_labels aag (\<lambda>x. x \<in> reads_scheduler aag l) s s' \<and>
(reads_scheduler_cur_domain aag l s \<or> reads_scheduler_cur_domain aag l s' \<longrightarrow>
work_units_completed s = work_units_completed s' \<and>
scheduler_globals_frame_equiv s s')"
lemma asahi_scheduler_affects_equiv_unobservable:
assumes a: "\<And>P Q R S X st. \<lbrace>states_equiv_for P Q R S st\<rbrace> f \<lbrace>\<lambda>_. states_equiv_for P Q R S st\<rbrace>"
assumes c: "\<And>P. \<lbrace>\<lambda>s. P (cur_domain s)\<rbrace> f \<lbrace>\<lambda>r s. P (cur_domain s)\<rbrace>"
assumes w: "\<And>P. \<lbrace>\<lambda>s. P (work_units_completed s)\<rbrace> f \<lbrace>\<lambda>r s. P (work_units_completed s)\<rbrace>"
shows "\<lbrace>asahi_scheduler_affects_equiv aag l st\<rbrace> f
\<lbrace>\<lambda>_. asahi_scheduler_affects_equiv aag l st\<rbrace>"
proof -
have d: "\<lbrace>scheduler_globals_frame_equiv st\<rbrace> f \<lbrace>\<lambda>_. scheduler_globals_frame_equiv st\<rbrace>"
apply (simp add: globals_frame_equiv_as_states_equiv[abs_def])
apply (clarsimp simp add: valid_def)
apply (frule use_valid[OF _ a])
apply assumption
apply (simp add: states_equiv_for_def equiv_for_def equiv_asids_def)
done
show ?thesis
apply (simp add: asahi_scheduler_affects_equiv_def[abs_def])
apply (rule hoare_pre)
apply (wps c)
apply (wp static_imp_wp a silc_dom_equiv_states_equiv_lift d w)
apply clarsimp
done
qed
lemma asahi_scheduler_affects_equiv_sym[elim]:
"asahi_scheduler_affects_equiv aag l s s' \<Longrightarrow> asahi_scheduler_affects_equiv aag l s' s"
apply (simp add: asahi_scheduler_affects_equiv_def)
apply (auto simp: scheduler_globals_frame_equiv_sym states_equiv_for_sym silc_dom_equiv_sym)
done
lemma asahi_scheduler_affects_equiv_trans[elim]:
"\<lbrakk>asahi_scheduler_affects_equiv aag l s s'; scheduler_equiv aag s s';
asahi_scheduler_affects_equiv aag l s' s''; scheduler_equiv aag s' s''\<rbrakk>
\<Longrightarrow> asahi_scheduler_affects_equiv aag l s s''"
apply (simp add: asahi_scheduler_affects_equiv_def scheduler_equiv_trans[where s'=s'])+
apply clarify
apply (rule conjI)
apply (rule states_equiv_for_trans[where t=s'])
apply simp+
apply (force simp: scheduler_globals_frame_equiv_trans[where s'=s'] scheduler_equiv_def
domain_fields_equiv_def)
done
definition asahi_ex_scheduler_affects_equiv ::
"'a subject_label PAS \<Rightarrow> 'a subject_label \<Rightarrow> det_ext state \<Rightarrow> det_ext state \<Rightarrow> bool"
where
"asahi_ex_scheduler_affects_equiv aag l s s' \<equiv>
states_equiv_for_labels aag (\<lambda>x. x \<in> reads_scheduler aag l) s s' \<and>
(reads_scheduler_cur_domain aag l s \<or> reads_scheduler_cur_domain aag l s' \<longrightarrow>
work_units_completed s = work_units_completed s' \<and>
scheduler_globals_frame_equiv s s' \<and>
exclusive_state_equiv s s')"
lemma asahi_ex_scheduler_affects_equiv_unobservable:
assumes a: "\<And>P Q R S X st. \<lbrace>states_equiv_for P Q R S st\<rbrace> f \<lbrace>\<lambda>_. states_equiv_for P Q R S st\<rbrace>"
assumes c: "\<And>P. \<lbrace>\<lambda>s. P (cur_domain s)\<rbrace> f \<lbrace>\<lambda>r s. P (cur_domain s)\<rbrace>"
assumes w: "\<And>P. \<lbrace>\<lambda>s. P (work_units_completed s)\<rbrace> f \<lbrace>\<lambda>r s. P (work_units_completed s)\<rbrace>"
assumes x:
"\<And>P. \<lbrace>\<lambda>s. P (exclusive_state (machine_state s))\<rbrace>
f
\<lbrace>\<lambda>r s. P (exclusive_state (machine_state s))\<rbrace>"
shows "\<lbrace>asahi_ex_scheduler_affects_equiv aag l st\<rbrace>
f
\<lbrace>\<lambda>_. asahi_ex_scheduler_affects_equiv aag l st\<rbrace>"
proof -
have d: "\<lbrace>scheduler_globals_frame_equiv st\<rbrace> f \<lbrace>\<lambda>_. scheduler_globals_frame_equiv st\<rbrace>"
apply (simp add: globals_frame_equiv_as_states_equiv[abs_def])
apply (clarsimp simp add: valid_def)
apply (frule use_valid[OF _ a])
apply assumption
apply (simp add: states_equiv_for_def equiv_for_def equiv_asids_def)
done
show ?thesis
apply (simp add: asahi_ex_scheduler_affects_equiv_def[abs_def])
apply (rule hoare_pre)
apply (wps c)
apply (wp static_imp_wp a silc_dom_equiv_states_equiv_lift d w x)
apply clarsimp
done
qed
lemma asahi_ex_scheduler_affects_equiv_sym[elim]:
"asahi_ex_scheduler_affects_equiv aag l s s' \<Longrightarrow> asahi_ex_scheduler_affects_equiv aag l s' s"
apply (simp add: asahi_ex_scheduler_affects_equiv_def)
apply (auto simp: scheduler_globals_frame_equiv_sym states_equiv_for_sym silc_dom_equiv_sym)
done
lemma asahi_ex_scheduler_affects_equiv_trans[elim]:
"\<lbrakk>asahi_ex_scheduler_affects_equiv aag l s s'; scheduler_equiv aag s s';
asahi_ex_scheduler_affects_equiv aag l s' s''; scheduler_equiv aag s' s''\<rbrakk>
\<Longrightarrow> asahi_ex_scheduler_affects_equiv aag l s s''"
apply (simp add: asahi_ex_scheduler_affects_equiv_def scheduler_equiv_trans[where s'=s'])+
apply clarify
apply (rule conjI)
apply (rule states_equiv_for_trans[where t=s'])
apply simp+
apply (force simp: scheduler_globals_frame_equiv_trans[where s'=s'] scheduler_equiv_def
domain_fields_equiv_def)
done
lemma ev_asahi_to_asahi_ex_dmo_clearExMonitor:
"equiv_valid (scheduler_equiv aag) (midstrength_scheduler_affects_equiv aag l)
(asahi_ex_scheduler_affects_equiv aag l)
\<top> (do_machine_op clearExMonitor)"
apply (simp add: clearExMonitor_def)
apply (wp dmo_ev)
apply (rule ev_modify)
apply clarsimp
apply (rule conjI)
apply (clarsimp simp: scheduler_equiv_def domain_fields_equiv_def globals_equiv_scheduler_def
silc_dom_equiv_def equiv_for_def)
apply (clarsimp simp: midstrength_scheduler_affects_equiv_def asahi_scheduler_affects_equiv_def
asahi_ex_scheduler_affects_equiv_def states_equiv_for_def equiv_for_def
equiv_asids_def equiv_asid_def scheduler_globals_frame_equiv_def
simp del: split_paired_All)
done
lemma ev_asahi_ex_to_full_fragement:
"equiv_valid (scheduler_equiv aag) (asahi_ex_scheduler_affects_equiv aag l)
(scheduler_affects_equiv aag l) \<top>
(do x \<leftarrow> modify (cur_thread_update (\<lambda>_. t));
set_scheduler_action resume_cur_thread
od)"
apply (clarsimp simp: gets_def get_def return_def select_f_def bind_def
set_scheduler_action_def assert_def simpler_modify_def fail_def)
apply (fold simpler_modify_def)
apply (rule ev_modify)
apply (clarsimp simp: scheduler_equiv_def domain_fields_equiv_def states_equiv_for_def
globals_equiv_scheduler_def scheduler_affects_equiv_def
equiv_for_def equiv_asids_def equiv_asid_def
scheduler_globals_frame_equiv_def silc_dom_equiv_def
weak_scheduler_affects_equiv_def
asahi_ex_scheduler_affects_equiv_def idle_equiv_def)
done
lemma store_cur_thread_fragment_midstrength_reads_respects:
"equiv_valid (scheduler_equiv aag) (midstrength_scheduler_affects_equiv aag l)
(scheduler_affects_equiv aag l) invs
(do y \<leftarrow> do_machine_op clearExMonitor;
x \<leftarrow> modify (cur_thread_update (\<lambda>_. t));
set_scheduler_action resume_cur_thread
od)"
apply (rule equiv_valid_guard_imp)
apply (rule bind_ev_general[OF ev_asahi_ex_to_full_fragement])
apply (rule ev_asahi_to_asahi_ex_dmo_clearExMonitor)
apply wp
apply simp
done
(*******************************)
lemma arch_switch_to_thread_globals_equiv_scheduler':
"\<lbrace>invs and globals_equiv_scheduler sta\<rbrace>
set_vm_root t
\<lbrace>\<lambda>_. globals_equiv_scheduler sta\<rbrace>"
by (rule globals_equiv_scheduler_inv', wpsimp)
lemma arch_switch_to_thread_reads_respects_scheduler[wp]:
"reads_respects_scheduler aag l ((\<lambda>s. pasObjectAbs aag t \<in> pasDomainAbs aag (cur_domain s)) and
invs)
(arch_switch_to_thread t)"
apply (rule reads_respects_scheduler_cases)
apply (simp add: arch_switch_to_thread_def)
apply wp
apply (clarsimp simp: scheduler_equiv_def globals_equiv_scheduler_def)
apply (simp add: arch_switch_to_thread_def)
apply wp
apply simp
done
lemma arch_switch_to_thread_pas_refined[wp]:
"\<lbrace>pas_refined aag\<rbrace>
arch_switch_to_thread t
\<lbrace>\<lambda>rv. pas_refined aag\<rbrace>"
unfolding arch_switch_to_thread_def
by (wp do_machine_op_pas_refined | simp)+
lemma cur_thread_update_idle_reads_respects_scheduler:
"reads_respects_scheduler aag l (\<lambda>s. t = idle_thread s)
(modify (cur_thread_update (\<lambda>_. t)))"
apply (rule ev_modify)
apply (clarsimp simp add: scheduler_affects_equiv_def
scheduler_equiv_def domain_fields_equiv_def
globals_equiv_scheduler_def states_equiv_for_def
equiv_for_def equiv_asids_def equiv_asid_def
scheduler_globals_frame_equiv_def idle_equiv_def)
done
lemma strong_cur_domain_unobservable:
"reads_respects_scheduler aag l
(P and (\<lambda>s. \<not> reads_scheduler_cur_domain aag l s)) f
\<Longrightarrow> strong_reads_respects_scheduler aag l
(P and (\<lambda>s. \<not> reads_scheduler_cur_domain aag l s)) f"
apply (clarsimp simp add: equiv_valid_def2 equiv_valid_2_def
scheduler_equiv_def domain_fields_equiv_def
scheduler_affects_equiv_def weak_scheduler_affects_equiv_def)
apply (drule_tac x=s in spec)
apply (drule_tac x=t in spec)
apply clarsimp
apply (drule_tac x="(a,b)" in bspec,clarsimp+)
apply (drule_tac x="(aa,ba)" in bspec,clarsimp+)
done
lemma midstrength_cur_domain_unobservable:
"reads_respects_scheduler aag l
(P and (\<lambda>s. \<not> reads_scheduler_cur_domain aag l s)) f
\<Longrightarrow> midstrength_reads_respects_scheduler aag l
(P and (\<lambda>s. \<not> reads_scheduler_cur_domain aag l s)) f"
apply (clarsimp simp add: equiv_valid_def2 equiv_valid_2_def
scheduler_equiv_def domain_fields_equiv_def
scheduler_affects_equiv_def midstrength_scheduler_affects_equiv_def)
apply (drule_tac x=s in spec)
apply (drule_tac x=t in spec)
apply clarsimp
apply (drule_tac x="(a,b)" in bspec,clarsimp+)
apply (drule_tac x="(aa,ba)" in bspec,clarsimp+)
done
lemma equiv_valid_get_assert:
"equiv_valid I A B P f \<Longrightarrow>
equiv_valid I A B P (get >>= (\<lambda> s. assert (g s) >>= (\<lambda> y. f)))"
apply (clarsimp simp: equiv_valid_def2 equiv_valid_2_def bind_def get_def
assert_def return_def fail_def)
apply fastforce
done
lemma midstrength_reads_respects_scheduler_cases:
assumes domains_distinct: "pas_domains_distinct aag"
assumes b:
"pasObjectAbs aag t \<in> reads_scheduler aag l
\<Longrightarrow> midstrength_reads_respects_scheduler aag l P' (f t)"
assumes b': "\<And>s. Q s \<Longrightarrow> pasObjectAbs aag t \<in> reads_scheduler aag l \<Longrightarrow> P' s"
assumes c:
"pasObjectAbs aag t \<notin> reads_scheduler aag l
\<Longrightarrow> reads_respects_scheduler aag l P'' (f t)"
assumes c': "\<And>s. Q s \<Longrightarrow> pasObjectAbs aag t \<notin> reads_scheduler aag l \<Longrightarrow> P'' s"
assumes d: "\<And>s. Q s \<Longrightarrow> pasObjectAbs aag t \<in> pasDomainAbs aag (cur_domain s)"
shows "midstrength_reads_respects_scheduler aag l Q (f t)"
apply (case_tac "pasObjectAbs aag t \<in> reads_scheduler aag l")
apply (rule equiv_valid_guard_imp)
apply (rule b)
apply simp+
apply (rule b')
apply simp+
apply (rule equiv_valid_guard_imp)