-
Notifications
You must be signed in to change notification settings - Fork 108
/
Scheduler_IF.thy
2436 lines (2154 loc) · 113 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 "ArchSyscall_IF" "ArchPasUpdates"
begin
(* After SELFOUR-553 scheduler no longer writes to shared memory *)
abbreviation scheduler_affects_globals_frame where
"scheduler_affects_globals_frame s \<equiv> {}"
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_state \<Rightarrow> det_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 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 idle_context where
"idle_context s = arch_tcb_context_get (tcb_arch (the (get_tcb (idle_thread s) s)))"
locale Scheduler_IF_1 =
fixes arch_globals_equiv_scheduler :: "kheap \<Rightarrow> kheap \<Rightarrow> arch_state \<Rightarrow> arch_state \<Rightarrow> bool"
and arch_scheduler_affects_equiv :: "det_state \<Rightarrow> det_state \<Rightarrow> bool"
assumes arch_globals_equiv_from_scheduler:
"\<lbrakk> arch_globals_equiv_scheduler (kheap s) (kheap s') (arch_state s) (arch_state s');
cur_thread s' \<noteq> idle_thread s \<longrightarrow> arch_scheduler_affects_equiv s s' \<rbrakk>
\<Longrightarrow> arch_globals_equiv (cur_thread s') (idle_thread s) (kheap s) (kheap s')
(arch_state s) (arch_state s') (machine_state s) (machine_state s')"
and arch_globals_equiv_scheduler_refl:
"arch_globals_equiv_scheduler (kheap s) (kheap s) (arch_state s) (arch_state s)"
and arch_globals_equiv_scheduler_sym:
"arch_globals_equiv_scheduler (kheap s) (kheap s') (arch_state s) (arch_state s')
\<Longrightarrow> arch_globals_equiv_scheduler (kheap s') (kheap s) (arch_state s') (arch_state s)"
and arch_globals_equiv_scheduler_trans:
"\<lbrakk> arch_globals_equiv_scheduler (kheap s) (kheap s') (arch_state s) (arch_state s');
arch_globals_equiv_scheduler (kheap s') (kheap s'') (arch_state s') (arch_state s'') \<rbrakk>
\<Longrightarrow> arch_globals_equiv_scheduler (kheap s) (kheap s'') (arch_state s) (arch_state s'')"
and arch_scheduler_affects_equiv_trans[elim]:
"\<lbrakk> arch_scheduler_affects_equiv s s'; arch_scheduler_affects_equiv s' s'' \<rbrakk>
\<Longrightarrow> arch_scheduler_affects_equiv s (s'' :: det_state)"
and arch_scheduler_affects_equiv_sym[elim]:
"arch_scheduler_affects_equiv s s' \<Longrightarrow> arch_scheduler_affects_equiv s' s"
and arch_scheduler_affects_equiv_update:
"arch_scheduler_affects_equiv st s
\<Longrightarrow> arch_scheduler_affects_equiv st (s\<lparr>kheap := (kheap s)(x \<mapsto> TCB y')\<rparr>)"
and arch_scheduler_affects_equiv_sa_update[simp]:
"\<And>f. arch_scheduler_affects_equiv (scheduler_action_update f s) s' =
arch_scheduler_affects_equiv s s'"
"\<And>f. arch_scheduler_affects_equiv s (scheduler_action_update f s') =
arch_scheduler_affects_equiv s s'"
and arch_scheduler_affects_equiv_ready_queues_update[simp]:
"\<And>f. arch_scheduler_affects_equiv (ready_queues_update f s) s' =
arch_scheduler_affects_equiv s s'"
"\<And>f. arch_scheduler_affects_equiv s (ready_queues_update f s') =
arch_scheduler_affects_equiv s s'"
and arch_scheduler_affects_equiv_cur_thread_update[simp]:
"\<And>f. arch_scheduler_affects_equiv (cur_thread_update f s) s' =
arch_scheduler_affects_equiv s s'"
"\<And>f. arch_scheduler_affects_equiv s (cur_thread_update f s') =
arch_scheduler_affects_equiv s s'"
and arch_scheduler_affects_equiv_domain_time_update[simp]:
"\<And>f. arch_scheduler_affects_equiv (domain_time_update f s) s' =
arch_scheduler_affects_equiv s s'"
"\<And>f. arch_scheduler_affects_equiv s (domain_time_update f s') =
arch_scheduler_affects_equiv s s'"
and arch_scheduler_affects_equiv_ekheap_update[simp]:
"\<And>f. arch_scheduler_affects_equiv (ekheap_update f s) s' =
arch_scheduler_affects_equiv s s'"
"\<And>f. arch_scheduler_affects_equiv s (ekheap_update f s') =
arch_scheduler_affects_equiv s s'"
and arch_switch_to_thread_kheap[wp]:
"\<And>P. arch_switch_to_thread t \<lbrace>\<lambda>s :: det_state. P (kheap s)\<rbrace>"
and arch_switch_to_idle_thread_kheap[wp]:
"\<And>P. arch_switch_to_idle_thread \<lbrace>\<lambda>s :: det_state. P (kheap s)\<rbrace>"
and arch_switch_to_thread_idle_thread[wp]:
"\<And>P. arch_switch_to_thread t \<lbrace>\<lambda>s :: det_state. P (idle_thread s)\<rbrace>"
and arch_switch_to_idle_thread_idle_thread[wp]:
"\<And>P. arch_switch_to_idle_thread \<lbrace>\<lambda>s :: det_state. P (idle_thread s)\<rbrace>"
and arch_switch_to_idle_thread_cur_domain[wp]:
"\<And>P. arch_switch_to_idle_thread \<lbrace>\<lambda>s. P (cur_domain s)\<rbrace>"
and arch_switch_to_idle_thread_domain_fields[wp]:
"\<And>P. arch_switch_to_idle_thread \<lbrace>\<lambda>s. P (domain_time s) (domain_index s) (domain_list s)\<rbrace>"
and arch_switch_to_idle_thread_globals_equiv[wp]:
"arch_switch_to_idle_thread \<lbrace>globals_equiv st\<rbrace>"
and arch_switch_to_idle_thread_states_equiv_for[wp]:
"\<And>P Q R S. arch_switch_to_idle_thread \<lbrace>states_equiv_for P Q R S st\<rbrace>"
and arch_switch_to_idle_thread_work_units_completed[wp]:
"\<And>P. arch_switch_to_idle_thread \<lbrace>\<lambda>s. P (work_units_completed s)\<rbrace>"
and equiv_asid_equiv_update:
"\<lbrakk> get_tcb x s = Some y; equiv_asid asid st s \<rbrakk>
\<Longrightarrow> equiv_asid asid st (s\<lparr>kheap := (kheap s)(x \<mapsto> TCB y')\<rparr>)"
and equiv_asid_cur_thread_update[simp]:
"\<And>f. equiv_asid asid (cur_thread_update f s) s' = equiv_asid asid s s'"
"\<And>f. equiv_asid asid s (cur_thread_update f s') = equiv_asid asid s s'"
and equiv_asid_domain_time_update[simp]:
"\<And>f. equiv_asid asid (domain_time_update f s) s' = equiv_asid asid s s'"
"\<And>f. equiv_asid asid s (domain_time_update f s') = equiv_asid asid s s'"
and equiv_asid_ekheap_update[simp]:
"\<And>f. equiv_asid asid (ekheap_update f s) s' = equiv_asid asid s s'"
"\<And>f. equiv_asid asid s (ekheap_update f s') = equiv_asid asid s s'"
and ackInterrupt_irq_state[wp]:
"\<And>P. ackInterrupt irq \<lbrace>\<lambda>s. P (irq_state s)\<rbrace>"
and thread_set_context_globals_equiv:
"\<lbrace>(\<lambda>s. t = idle_thread s \<longrightarrow> tc = idle_context s) and invs and globals_equiv st\<rbrace>
thread_set (tcb_arch_update (arch_tcb_context_set tc)) t
\<lbrace>\<lambda>rv. globals_equiv st\<rbrace>"
and arch_activate_idle_thread_cur_domain[wp]:
"\<And>P. arch_activate_idle_thread t \<lbrace>\<lambda>s. P (cur_domain s)\<rbrace>"
and arch_activate_idle_thread_idle_thread[wp]:
"\<And>P. arch_activate_idle_thread t \<lbrace>\<lambda>s :: det_state. P (idle_thread s)\<rbrace>"
and arch_activate_idle_thread_irq_state_of_state[wp]:
"\<And>P. arch_activate_idle_thread t \<lbrace>\<lambda>s. P (irq_state_of_state s)\<rbrace>"
and arch_activate_idle_thread_domain_fields[wp]:
"\<And>P. arch_activate_idle_thread t \<lbrace>domain_fields P\<rbrace>"
begin
definition globals_equiv_scheduler :: "det_state \<Rightarrow> det_state \<Rightarrow> bool" where
"globals_equiv_scheduler s s' \<equiv>
arch_globals_equiv_scheduler (kheap s) (kheap s') (arch_state s) (arch_state s') \<and>
idle_equiv s s' \<and> device_region s = device_region s'"
definition scheduler_equiv :: "'a subject_label PAS \<Rightarrow> det_state \<Rightarrow> det_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'"
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> arch_scheduler_affects_equiv s s'))))"
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> arch_scheduler_affects_equiv s s' \<rbrakk>
\<Longrightarrow> globals_equiv s s'"
by (clarsimp simp: globals_equiv_scheduler_def scheduler_globals_frame_equiv_def
globals_equiv_def arch_globals_equiv_from_scheduler)
lemma globals_equiv_scheduler_refl:
"globals_equiv_scheduler s s"
by (simp add: globals_equiv_scheduler_def idle_equiv_refl arch_globals_equiv_scheduler_refl)
lemma globals_equiv_scheduler_sym[elim]:
"globals_equiv_scheduler s s' \<Longrightarrow> globals_equiv_scheduler s' s"
by (auto simp: globals_equiv_scheduler_def idle_equiv_sym arch_globals_equiv_scheduler_sym)
lemma globals_equiv_scheduler_trans[elim]:
"\<lbrakk> globals_equiv_scheduler s s'; globals_equiv_scheduler s' s'' \<rbrakk>
\<Longrightarrow> globals_equiv_scheduler s s''"
unfolding globals_equiv_scheduler_def
by (fastforce elim: arch_globals_equiv_scheduler_trans idle_equiv_trans)
end
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]:
"\<lbrakk> scheduler_globals_frame_equiv s s'; scheduler_globals_frame_equiv s' s'' \<rbrakk>
\<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
by (blast intro: preserves_equivalence_2_weak)
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
context Scheduler_IF_1 begin
lemma scheduler_equiv_trans[elim]:
"\<lbrakk> scheduler_equiv aag s s'; scheduler_equiv aag s' s'' \<rbrakk>
\<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 (clarsimp simp: scheduler_globals_frame_equiv_trans[where s'=s']
scheduler_equiv_def domain_fields_equiv_def)
apply (erule (1) arch_scheduler_affects_equiv_trans)
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
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. f \<lbrace>\<lambda>s. P (idle_thread s)\<rbrace>"
assumes e: "\<And>Q. \<lbrace>P and domain_fields Q\<rbrace> f \<lbrace>\<lambda>_. domain_fields Q\<rbrace>"
assumes g: "\<And>P. f \<lbrace>\<lambda>s. P (irq_state_of_state s)\<rbrace>"
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 reads_respects_scheduler_unobservable'':
assumes "\<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>"
assumes "\<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>"
assumes "\<And>s. Q s \<Longrightarrow> P s \<and> P' s"
shows "reads_respects_scheduler aag l Q f"
by (rule equiv_valid_inv_unobservable) (wp assms | force)+
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)"
by (rule reads_respects_scheduler_unobservable'') (wp f g | force)+
end
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 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 set_scheduler_action
for silc_dom_equiv[wp]: "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 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 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 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)
lemma (in is_extended') silc_dom_equiv[wp]:
"I (silc_dom_equiv aag st)"
by (rule lift_inv,simp)
context Scheduler_IF_1 begin
lemma set_scheduler_action_rev_scheduler[wp]:
"reads_respects_scheduler aag l \<top> (set_scheduler_action a)"
apply (clarsimp simp: set_scheduler_action_def)
apply (rule ev_modify)
by (clarsimp simp: scheduler_affects_equiv_def scheduler_equiv_def states_equiv_for_def
equiv_asids_def domain_fields_equiv_def globals_equiv_scheduler_def
silc_dom_equiv_def scheduler_globals_frame_equiv_def equiv_for_def)
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)
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
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 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: 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 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)
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. f \<lbrace>\<lambda>ms. P (underlying_memory ms)\<rbrace>"
and b: "\<And>P. f \<lbrace>\<lambda>ms. P (device_state ms)\<rbrace>"
shows "do_machine_op f \<lbrace>globals_equiv_scheduler s\<rbrace>"
unfolding do_machine_op_def
apply (rule hoare_pre)
apply (wp | simp add: split_def)+
apply clarsimp
apply (frule_tac P4 = "\<lambda>um. um = underlying_memory (machine_state sa)" in use_valid[OF _ a])
apply simp
apply (frule_tac P4 = "\<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
end
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')"
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 (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"
by (simp add: states_equiv_for_def equiv_for_def silc_dom_equiv_def equiv_asids_def)
lemma silc_dom_equiv_states_equiv_lift:
assumes a: "\<And>P Q R S st. f \<lbrace>states_equiv_for P Q R S st\<rbrace>"
shows "f \<lbrace>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
context Scheduler_IF_1 begin
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: do_machine_op_def bind_def gets_def get_def return_def select_f_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
scheduler_affects_equiv_def states_equiv_for_def idle_equiv_def equiv_for_def
equiv_asids_def scheduler_globals_frame_equiv_def silc_dom_equiv_def
weak_scheduler_affects_equiv_def midstrength_scheduler_affects_equiv_def)
done
lemma scheduler_affects_equiv_unobservable:
assumes a: "\<And>P Q R S st. f \<lbrace>states_equiv_for P Q R S st\<rbrace>"
assumes c: "\<And>P. f \<lbrace>\<lambda>s. P (cur_domain s)\<rbrace>"
assumes e: "\<And>P. f \<lbrace>\<lambda>s. P (cur_thread s)\<rbrace>"
assumes s: "\<And>P. f \<lbrace>\<lambda>s. P (scheduler_action s)\<rbrace>"
assumes w: "\<And>P. f \<lbrace>\<lambda>s. P (work_units_completed s)\<rbrace>"
assumes i: "\<And>P. f \<lbrace>\<lambda>s. P (idle_thread s)\<rbrace>"
assumes x: "f \<lbrace>arch_scheduler_affects_equiv st\<rbrace>"
shows "f \<lbrace>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 hoare_weak_lift_imp 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. f \<lbrace>states_equiv_for P Q R S st\<rbrace>"
assumes w: "\<And>P. f \<lbrace>\<lambda>s. P (cur_domain s) (work_units_completed s)\<rbrace>"
shows "f \<lbrace>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 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 (wpsimp simp: scheduler_affects_equiv_def states_equiv_for_def equiv_for_def get_tcb_def)
done
crunch guarded_switch_to,schedule
for idle_thread[wp]: "\<lambda>(s :: det_state). P (idle_thread s)"
(wp: crunch_wps simp: crunch_simps)
crunch guarded_switch_to, schedule
for kheap[wp]: "\<lambda>s :: det_state. P (kheap s)"
(wp: dxo_wp_weak crunch_wps simp: crunch_simps)
end
lemma silc_dom_lift:
assumes a: "\<And>P. f \<lbrace>\<lambda>s. P (kheap s)\<rbrace>"
shows "f \<lbrace>silc_dom_equiv aag st\<rbrace>"
by (wpsimp wp: a simp: silc_dom_equiv_def equiv_for_def[abs_def])
lemma dmo_silc_dom[wp]:
"do_machine_op mop \<lbrace>silc_dom_equiv aag st\<rbrace>"
by (wp silc_dom_lift)
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 st. f \<lbrace>states_equiv_for P Q R S st\<rbrace>"
assumes c: "\<And>P. f \<lbrace>\<lambda>s. P (cur_domain s)\<rbrace>"
assumes w: "\<And>P. f \<lbrace>\<lambda>s. P (work_units_completed s)\<rbrace>"
shows "f \<lbrace>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 hoare_weak_lift_imp 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 midstrength_weak[intro]:
"midstrength_scheduler_affects_equiv aag l s s' \<Longrightarrow> weak_scheduler_affects_equiv aag l s s'"
by (auto simp: midstrength_scheduler_affects_equiv_def weak_scheduler_affects_equiv_def)
context Scheduler_IF_1 begin
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_state \<Rightarrow> det_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>
arch_scheduler_affects_equiv s s')"
lemma asahi_ex_scheduler_affects_equiv_unobservable:
assumes a: "\<And>P Q R S st. f \<lbrace>states_equiv_for P Q R S st\<rbrace>"
assumes c: "\<And>P. f \<lbrace>\<lambda>s. P (cur_domain s)\<rbrace>"
assumes w: "\<And>P. f \<lbrace>\<lambda>s. P (work_units_completed s)\<rbrace>"
assumes x: "f \<lbrace>arch_scheduler_affects_equiv st\<rbrace>"
shows "f \<lbrace>asahi_ex_scheduler_affects_equiv aag l st\<rbrace>"
proof -
have d: "f \<lbrace>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 hoare_weak_lift_imp a silc_dom_equiv_states_equiv_lift d w x hoare_vcg_imp_lift')
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 (auto intro: arch_scheduler_affects_equiv_trans
simp: scheduler_globals_frame_equiv_trans[where s'=s']
scheduler_equiv_def domain_fields_equiv_def)
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
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 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
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: scheduler_equiv_def domain_fields_equiv_def scheduler_affects_equiv_def
equiv_valid_def2 equiv_valid_2_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: scheduler_equiv_def domain_fields_equiv_def scheduler_affects_equiv_def
equiv_valid_def2 equiv_valid_2_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 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)
apply (rule midstrength_cur_domain_unobservable)
apply (rule equiv_valid_guard_imp)
apply (rule c)
apply simp+
apply fastforce
apply clarsimp
apply (rule conjI)
apply (rule c')
apply simp+
apply (fastforce dest: d domains_distinct[THEN pas_domains_distinct_inj])
done
lemma thread_get_weak_reads_respects_scheduler[wp]:
"weak_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 (simp add: weak_scheduler_affects_equiv_def states_equiv_for_def equiv_for_def get_tcb_def)
done
lemma weak_reads_respects_scheduler_to_midstrength:
assumes w: "weak_reads_respects_scheduler aag l P f"
assumes i: "\<And>P. \<lbrace>P\<rbrace> f \<lbrace>\<lambda>_. P\<rbrace>"
shows "equiv_valid_inv (scheduler_equiv aag)
(midstrength_scheduler_affects_equiv aag l) P f"
apply (clarsimp simp: equiv_valid_def2 equiv_valid_2_def)
apply (rule conjI)
apply (insert w)[1]
apply (fastforce simp: equiv_valid_def2 equiv_valid_2_def)
apply (blast dest: state_unchanged[OF i])
done
lemma midstrength_scheduler_affects_equiv_trans[elim]:
"\<lbrakk> scheduler_equiv aag s s'; midstrength_scheduler_affects_equiv aag l s s';
scheduler_equiv aag s' s''; midstrength_scheduler_affects_equiv aag l s' s'' \<rbrakk>
\<Longrightarrow> midstrength_scheduler_affects_equiv aag l s s''"
apply (simp add: midstrength_scheduler_affects_equiv_def
scheduler_equiv_def domain_fields_equiv_def)
apply (fastforce intro: states_equiv_for_trans)
done
lemma cur_thread_update_not_subject_reads_respects_scheduler:
assumes domains_distinct: "pas_domains_distinct aag"
shows
"reads_respects_scheduler aag l (\<lambda>s. pasObjectAbs aag t \<notin> reads_scheduler aag l \<and>
pasObjectAbs aag t \<in> pasDomainAbs aag (cur_domain s))
(modify (cur_thread_update (\<lambda>_. t)))"
apply (rule ev_modify)
apply (clarsimp simp: 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 scheduler_globals_frame_equiv_def idle_equiv_def)
apply (blast dest: domains_distinct[THEN pas_domains_distinct_inj])
done
lemma gets_evrv':
"equiv_valid_rv I A B R (K (\<forall>s t. I s t \<and> A s t \<longrightarrow> R (f s) (f t) \<and> B s t)) (gets f)"
apply (auto simp: equiv_valid_2_def in_monad)
done
lemma gets_ev_no_inv:
shows "equiv_valid I A B (\<lambda> s. \<forall>s t. I s t \<and> A s t \<longrightarrow> f s = f t \<and> B s t) (gets f)"
apply (simp add: equiv_valid_def2)
apply (auto intro: equiv_valid_rv_guard_imp[OF gets_evrv'])
done
lemmas reads_respects_scheduler_unobservable =
reads_respects_scheduler_unobservable'[where P="\<top>",simplified]
end
lemma weak_scheduler_affects_equiv_trans[elim]:
"\<lbrakk> weak_scheduler_affects_equiv aag l s s'; weak_scheduler_affects_equiv aag l s' s'' \<rbrakk>
\<Longrightarrow> weak_scheduler_affects_equiv aag l s s''"
apply (simp add: weak_scheduler_affects_equiv_def)
apply (fastforce intro: states_equiv_for_trans)
done
lemma weak_scheduler_affects_equiv_sym[elim]:
"weak_scheduler_affects_equiv aag l s s' \<Longrightarrow> weak_scheduler_affects_equiv aag l s' s"
apply (simp add: weak_scheduler_affects_equiv_def)
apply (fastforce intro: states_equiv_for_sym)
done
lemma midstrength_scheduler_affects_equiv_sym[elim]:
"midstrength_scheduler_affects_equiv aag l s s'
\<Longrightarrow> midstrength_scheduler_affects_equiv aag l s' s"
apply (simp add: midstrength_scheduler_affects_equiv_def)
apply (fastforce intro: states_equiv_for_sym)
done
lemma ethread_get_oblivious_cur_thread:
"oblivious (cur_thread_update f) (ethread_get a b)"
by (wpsimp wp: oblivious_bind simp: ethread_get_def gets_the_def get_etcb_def)
lemma ethread_get_oblivious_schact:
"oblivious (scheduler_action_update f) (ethread_get a b)"
by (wpsimp wp: oblivious_bind simp: ethread_get_def gets_the_def get_etcb_def)
lemma tcb_action_oblivious_cur_thread:
"oblivious (cur_thread_update a) (tcb_sched_action f t)"
apply (simp add: tcb_sched_action_def)
apply (wp oblivious_bind ethread_get_oblivious_cur_thread
| clarsimp simp: get_tcb_queue_def set_tcb_queue_def)+
apply (fastforce intro: state.equality det_ext.equality)
done
lemma tcb_action_oblivious_schact:
"oblivious (scheduler_action_update a) (tcb_sched_action f t)"
apply (simp add: tcb_sched_action_def)
apply (wp oblivious_bind ethread_get_oblivious_schact
| clarsimp simp: get_tcb_queue_def set_tcb_queue_def)+
apply (fastforce intro: state.equality det_ext.equality)
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)))"
by (fastforce simp: equiv_valid_def2 equiv_valid_2_def bind_def
get_def assert_def return_def fail_def)
lemma ev_irrelevant_bind:
assumes inv: "\<And>P. f \<lbrace>P\<rbrace>"
assumes ev: "equiv_valid I A B P g"
shows "equiv_valid I A B P (do y \<leftarrow> f; g od)"
proof -
have a: "\<And>a b s. (a,b) \<in> fst (f s) \<Longrightarrow> b = s"
apply (erule use_valid[OF _ inv])
apply simp
done
show ?thesis
apply (insert ev)
apply (clarsimp simp add: equiv_valid_def2 equiv_valid_2_def
bind_def)
apply (drule a)+
apply clarsimp
apply fastforce
done
qed
locale Scheduler_IF_is_extended' = is_extended' + Scheduler_IF_1
begin
lemma globals_equiv_scheduler[wp]:
"I (globals_equiv_scheduler st)"
by (rule lift_inv, simp)
end
sublocale Scheduler_IF_1 \<subseteq> tcb_sched_action_extended:
Scheduler_IF_is_extended' "tcb_sched_action a t" ..
sublocale Scheduler_IF_1 \<subseteq> set_scheduler_action_extended:
Scheduler_IF_is_extended' "set_scheduler_action a" ..
sublocale Scheduler_IF_1 \<subseteq> next_domain_extended:
Scheduler_IF_is_extended' "next_domain" ..
sublocale Scheduler_IF_1 \<subseteq> ethread_set_extended:
Scheduler_IF_is_extended' "ethread_set f t" ..
sublocale Scheduler_IF_1 \<subseteq> reschedule_required_extended:
Scheduler_IF_is_extended' "reschedule_required" ..
locale Scheduler_IF_2 = Scheduler_IF_1 +
fixes aag :: "'a subject_label PAS"
assumes 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>"