-
Notifications
You must be signed in to change notification settings - Fork 0
/
IpcCancel_C.thy
2404 lines (2273 loc) · 110 KB
/
IpcCancel_C.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 2014, General Dynamics C4 Systems
*
* This software may be distributed and modified according to the terms of
* the GNU General Public License version 2. Note that NO WARRANTY is provided.
* See "LICENSE_GPLv2.txt" for details.
*
* @TAG(GD_GPL)
*)
theory IpcCancel_C
imports SyscallArgs_C
begin
context kernel_m
begin
lemma cready_queues_index_to_C_in_range':
assumes prems: "qdom \<le> ucast maxDom" "prio \<le> ucast maxPrio"
shows "cready_queues_index_to_C qdom prio < numDomains * numPriorities"
proof -
have P: "unat prio < numPriorities"
using prems
by (simp add: numPriorities_def seL4_MaxPrio_def Suc_le_lessD unat_le_helper)
have Q: "unat qdom < numDomains"
using prems
by (simp add: numDomains_def maxDom_def Suc_le_lessD unat_le_helper)
show ?thesis
using mod_lemma[OF _ P, where q="unat qdom" and c=numDomains] mod_less[OF Q]
by (clarsimp simp: cready_queues_index_to_C_def field_simps numDomains_def)
qed
lemmas cready_queues_index_to_C_in_range
= cready_queues_index_to_C_in_range'[unfolded numPriorities_def numDomains_def, simplified]
lemma cready_queues_index_to_C_inj:
"\<lbrakk> cready_queues_index_to_C qdom prio = cready_queues_index_to_C qdom' prio';
prio \<le> ucast maxPrio; prio' \<le> ucast maxPrio \<rbrakk> \<Longrightarrow> prio = prio' \<and> qdom = qdom'"
apply (rule context_conjI)
apply (auto simp: cready_queues_index_to_C_def numPriorities_def
seL4_MaxPrio_def word_le_nat_alt dest: arg_cong[where f="\<lambda>x. x mod 256"])
done
lemma cready_queues_index_to_C_distinct:
"\<lbrakk> qdom = qdom' \<longrightarrow> prio \<noteq> prio'; prio \<le> ucast maxPrio; prio' \<le> ucast maxPrio \<rbrakk>
\<Longrightarrow> cready_queues_index_to_C qdom prio \<noteq> cready_queues_index_to_C qdom' prio'"
apply (auto simp: cready_queues_index_to_C_inj)
done
lemma cstate_relation_ksReadyQueues_update:
"\<lbrakk> cstate_relation hs cs; arr = ksReadyQueues_' cs;
sched_queue_relation' (clift (t_hrs_' cs)) v (head_C v') (end_C v');
qdom \<le> ucast maxDom; prio \<le> ucast maxPrio \<rbrakk>
\<Longrightarrow> cstate_relation (ksReadyQueues_update (\<lambda>qs. qs ((qdom, prio) := v)) hs)
(ksReadyQueues_'_update (\<lambda>_. Arrays.update arr
(cready_queues_index_to_C qdom prio) v') cs)"
apply (clarsimp simp: cstate_relation_def Let_def
cmachine_state_relation_def
carch_state_relation_def carch_globals_def
cready_queues_relation_def seL4_MinPrio_def minDom_def)
apply (frule cready_queues_index_to_C_in_range, assumption)
apply clarsimp
apply (frule_tac qdom=qdoma and prio=prioa in cready_queues_index_to_C_in_range, assumption)
apply (frule cready_queues_index_to_C_distinct, assumption+)
apply clarsimp
done
lemma cmap_relation_drop_fun_upd:
"\<lbrakk> cm x = Some v; \<And>v''. rel v'' v = rel v'' v' \<rbrakk>
\<Longrightarrow> cmap_relation am (cm (x \<mapsto> v')) f rel
= cmap_relation am cm f rel"
apply (simp add: cmap_relation_def)
apply (rule conj_cong[OF refl])
apply (rule ball_cong[OF refl])
apply (auto split: split_if)
done
lemma valid_queuesD':
"\<lbrakk> obj_at' (inQ d p) t s; valid_queues' s \<rbrakk>
\<Longrightarrow> t \<in> set (ksReadyQueues s (d, p))"
by (simp add: valid_queues'_def)
lemma invs_valid_queues'[elim!]:
"invs' s \<Longrightarrow> valid_queues' s"
by (simp add: invs'_def valid_state'_def)
lemma aep_ptr_get_queue_spec:
"\<forall>s. \<Gamma> \<turnstile> {\<sigma>. s = \<sigma> \<and> \<sigma> \<Turnstile>\<^sub>c \<^bsup>\<sigma>\<^esup>aepptr} \<acute>ret__struct_tcb_queue_C :== PROC aep_ptr_get_queue(\<acute>aepptr)
\<lbrace>head_C \<acute>ret__struct_tcb_queue_C = Ptr (aepQueue_head_CL (async_endpoint_lift (the (cslift s \<^bsup>s\<^esup>aepptr)))) \<and>
end_C \<acute>ret__struct_tcb_queue_C = Ptr (aepQueue_tail_CL (async_endpoint_lift (the (cslift s \<^bsup>s\<^esup>aepptr))))\<rbrace>"
apply vcg
apply clarsimp
done
declare td_names_word8[simp]
lemma tcbEPDequeue_spec:
"\<forall>s queue. \<Gamma> \<turnstile> \<lbrace>s. \<exists>t. (t, s) \<in> rf_sr
\<and> (\<forall>tcb\<in>set queue. tcb_at' tcb t) \<and> distinct queue
\<and> (ctcb_ptr_to_tcb_ptr \<acute>tcb \<in> set queue)
\<and> ep_queue_relation' (cslift s) queue (head_C \<acute>queue) (end_C \<acute>queue) \<rbrace>
Call tcbEPDequeue_'proc
{t. (head_C (ret__struct_tcb_queue_C_' t) =
(if (tcbEPPrev_C (the (cslift s (\<^bsup>s\<^esup>tcb)))) = NULL then
(tcbEPNext_C (the (cslift s (\<^bsup>s\<^esup>tcb))))
else
(head_C \<^bsup>s\<^esup>queue)))
\<and> (end_C (ret__struct_tcb_queue_C_' t) =
(if (tcbEPNext_C (the (cslift s (\<^bsup>s\<^esup>tcb)))) = NULL then
(tcbEPPrev_C (the (cslift s (\<^bsup>s\<^esup>tcb))))
else
(end_C \<^bsup>s\<^esup>queue)))
\<and> (ep_queue_relation' (cslift t) (Lib.delete (ctcb_ptr_to_tcb_ptr \<^bsup>s\<^esup>tcb) queue) (head_C (ret__struct_tcb_queue_C_' t)) (end_C (ret__struct_tcb_queue_C_' t))
\<and> (cslift t |` (- tcb_ptr_to_ctcb_ptr ` set queue)) =
(cslift s |` (- tcb_ptr_to_ctcb_ptr ` set queue))
\<and> option_map tcb_null_ep_ptrs \<circ> (cslift t) =
option_map tcb_null_ep_ptrs \<circ> (cslift s))
\<and> cslift_all_but_tcb_C t s \<and> (hrs_htd \<^bsup>t\<^esup>t_hrs) = (hrs_htd \<^bsup>s\<^esup>t_hrs)}"
apply (intro allI)
apply (rule conseqPre)
apply vcg
apply (clarsimp split del: split_if)
apply (frule (4) tcb_queue_valid_ptrsD [OF _ _ _ _ tcb_queue_relation'_queue_rel])
apply (elim conjE exE)
apply (frule (3) tcbEPDequeue_update)
apply simp
apply (unfold upd_unless_null_def)
apply (frule (2) tcb_queue_relation_ptr_rel' [OF tcb_queue_relation'_queue_rel])
prefer 2
apply assumption
apply simp
apply (frule c_guard_clift)
apply (simp add: typ_heap_simps)
apply (intro allI conjI impI)
apply (clarsimp simp add: typ_heap_simps h_t_valid_clift_Some_iff)
apply (clarsimp simp: typ_heap_simps h_t_valid_clift_Some_iff
cong: if_weak_cong)
apply (rule ext)
apply (clarsimp simp add: typ_heap_simps h_t_valid_clift_Some_iff tcb_null_ep_ptrs_def)
apply (clarsimp simp add: typ_heap_simps h_t_valid_clift_Some_iff)
apply (clarsimp simp add: typ_heap_simps h_t_valid_clift_Some_iff)
apply (rule ext)
apply (clarsimp simp: typ_heap_simps h_t_valid_clift_Some_iff tcb_null_ep_ptrs_def
cong: if_weak_cong)
apply (rule ext)
apply (clarsimp simp add: typ_heap_simps h_t_valid_clift_Some_iff tcb_null_ep_ptrs_def)
apply (clarsimp simp add: typ_heap_simps h_t_valid_clift_Some_iff)
apply (clarsimp simp: typ_heap_simps h_t_valid_clift_Some_iff
cong: if_weak_cong)
apply (rule ext)
apply (clarsimp simp add: typ_heap_simps h_t_valid_clift_Some_iff tcb_null_ep_ptrs_def)
apply simp
done
lemma aep_ptr_set_queue_spec:
"\<forall>s. \<Gamma> \<turnstile> \<lbrace>s. s \<Turnstile>\<^sub>c \<acute>aepptr\<rbrace> Call aep_ptr_set_queue_'proc
{t. (\<exists>aep'. async_endpoint_lift aep' =
(async_endpoint_lift (the (cslift s (\<^bsup>s\<^esup>aepptr))))\<lparr> aepQueue_head_CL := ptr_val (head_C \<^bsup>s\<^esup>aep_queue) && ~~ mask 4,
aepQueue_tail_CL := ptr_val (end_C \<^bsup>s\<^esup>aep_queue) && ~~ mask 4 \<rparr> \<and>
(cslift t :: async_endpoint_C typ_heap) = (cslift s)(\<^bsup>s\<^esup>aepptr \<mapsto> aep'))
\<and> cslift_all_but_async_endpoint_C t s \<and> (hrs_htd \<^bsup>t\<^esup>t_hrs) = (hrs_htd \<^bsup>s\<^esup>t_hrs)}"
apply vcg
apply (auto simp: split_def h_t_valid_clift_Some_iff)
done
lemma asyncIPCCancel_ccorres_helper:
"ccorres dc xfdc (invs' and st_tcb_at' (op = (BlockedOnAsyncEvent aep)) thread and ko_at' aep' aep)
UNIV
[]
(setAsyncEP aep
(if remove1 thread (aepQueue aep') = []
then async_endpoint.IdleAEP
else aepQueue_update (\<lambda>_. remove1 thread (aepQueue aep')) aep'))
(\<acute>aep_queue :== CALL aep_ptr_get_queue(Ptr aep);;
\<acute>aep_queue :== CALL tcbEPDequeue(tcb_ptr_to_ctcb_ptr thread,\<acute>aep_queue);;
CALL aep_ptr_set_queue(Ptr aep,\<acute>aep_queue);;
IF head_C \<acute>aep_queue = NULL THEN
CALL async_endpoint_ptr_set_state(Ptr aep,
scast AEPState_Idle)
FI)"
apply (rule ccorres_from_vcg)
apply (rule allI, rule conseqPre, vcg)
apply (clarsimp split del: split_if simp del: comp_def)
apply (frule (2) aep_blocked_in_queueD)
apply (frule (1) ko_at_valid_aep' [OF _ invs_valid_objs'])
apply (elim conjE)
apply (frule (1) valid_aep_isWaitingAEPD)
apply (elim conjE)
apply (frule cmap_relation_aep)
apply (erule (1) cmap_relation_ko_atE)
apply (rule conjI)
apply (erule h_t_valid_clift)
apply (rule impI)
apply (rule exI)
apply (rule conjI)
apply (rule_tac x = \<sigma> in exI)
apply (intro conjI, assumption+)
apply (drule (2) aep_to_ep_queue)
apply (simp add: tcb_queue_relation'_def)
apply (clarsimp simp: typ_heap_simps cong: imp_cong split del: split_if simp del: comp_def)
apply (frule null_ep_queue [simplified Fun.comp_def])
apply (intro impI conjI allI)
-- "empty case"
apply clarsimp
apply (frule iffD1 [OF tcb_queue_head_empty_iff [OF tcb_queue_relation'_queue_rel]])
apply (rule ballI, erule bspec)
apply (erule subsetD [rotated])
apply clarsimp
apply simp
apply (simp add: setAsyncEP_def split_def)
apply (rule bexI [OF _ setObject_eq])
apply (simp add: remove1_empty rf_sr_def cstate_relation_def Let_def cpspace_relation_def update_aep_map_tos)
apply (elim conjE)
apply (intro conjI)
-- "tcb relation"
apply (erule ctcb_relation_null_queue_ptrs)
apply (clarsimp simp: comp_def)
-- "ep relation"
apply (erule iffD1 [OF cmap_relation_cong, OF refl refl, rotated -1])
apply simp
apply (rule cendpoint_relation_aep_queue [OF invs_sym'], assumption+)
apply simp
apply (erule (1) map_to_ko_atI')
-- "aep relation"
apply (rule cpspace_relation_aep_update_aep, assumption+)
apply (simp add: casync_endpoint_relation_def Let_def AEPState_Idle_def)
apply (simp add: carch_state_relation_def carch_globals_def)
-- "queue relation"
apply (rule cready_queues_relation_null_queue_ptrs, assumption+)
apply (clarsimp simp: comp_def)
apply (simp add: carch_state_relation_def carch_globals_def)
apply (simp add: cmachine_state_relation_def)
apply (simp add: h_t_valid_clift_Some_iff)
apply (simp add: objBits_simps)
apply (simp add: objBits_simps)
apply assumption
-- "non empty case"
apply clarsimp
apply (frule tcb_queue_head_empty_iff [OF tcb_queue_relation'_queue_rel])
apply (rule ballI, erule bspec)
apply (erule subsetD [rotated])
apply clarsimp
apply (simp add: setAsyncEP_def split_def)
apply (rule bexI [OF _ setObject_eq])
apply (frule (1) st_tcb_at_h_t_valid)
apply (simp add: remove1_empty rf_sr_def cstate_relation_def Let_def cpspace_relation_def update_aep_map_tos)
apply (elim conjE)
apply (intro conjI)
-- "tcb relation"
apply (erule ctcb_relation_null_queue_ptrs)
apply (clarsimp simp: comp_def)
-- "ep relation"
apply (erule iffD1 [OF cmap_relation_cong, OF refl refl, rotated -1])
apply simp
apply (rule cendpoint_relation_aep_queue)
apply fastforce
apply assumption+
apply simp
apply (erule (1) map_to_ko_atI')
-- "aep relation"
apply (rule cpspace_relation_aep_update_aep, assumption+)
apply (simp add: casync_endpoint_relation_def Let_def isWaitingAEP_def split: async_endpoint.splits split del: split_if)
apply (erule iffD1 [OF tcb_queue_relation'_cong [OF refl _ _ refl], rotated -1])
apply (clarsimp simp add: Ptr_ptr_val h_t_valid_clift_Some_iff)
apply (simp add: tcb_queue_relation'_next_mask_4)
apply (clarsimp simp add: Ptr_ptr_val h_t_valid_clift_Some_iff)
apply (simp add: tcb_queue_relation'_prev_mask_4)
apply simp
-- "queue relation"
apply (rule cready_queues_relation_null_queue_ptrs, assumption+)
apply (clarsimp simp: comp_def)
apply (simp add: carch_state_relation_def carch_globals_def)
apply (simp add: cmachine_state_relation_def)
apply (simp add: h_t_valid_clift_Some_iff)
apply (simp add: objBits_simps)
apply (simp add: objBits_simps)
apply assumption
done
lemma threadSet_tcbState_simple_corres:
"ccorres dc xfdc (tcb_at' thread)
{s. (\<forall>cl fl. cthread_state_relation_lifted st (cl\<lparr>tsType_CL := v_' s && mask 4\<rparr>, fl)) \<and>
thread_state_ptr_' s = Ptr &(tcb_ptr_to_ctcb_ptr thread\<rightarrow>[''tcbState_C''])} []
(threadSet (tcbState_update (\<lambda>_. st)) thread) (Call thread_state_ptr_set_tsType_'proc)"
apply (rule threadSet_corres_lemma)
apply (rule thread_state_ptr_set_tsType_spec)
apply (rule thread_state_ptr_set_tsType_modifies)
apply clarsimp
apply (frule (1) obj_at_cslift_tcb)
apply clarsimp
apply (rule rf_sr_tcb_update_no_queue, assumption+, simp_all)
apply (rule ball_tcb_cte_casesI, simp_all)
apply (frule cmap_relation_tcb)
apply (frule (1) cmap_relation_ko_atD)
apply clarsimp
apply (simp add: ctcb_relation_def cthread_state_relation_def)
apply (frule (1) obj_at_cslift_tcb)
apply (clarsimp simp: typ_heap_simps)
done
lemma ko_at_obj_congD':
"\<lbrakk>ko_at' k p s; ko_at' k' p s\<rbrakk> \<Longrightarrow> k = k'"
apply (erule obj_atE')+
apply simp
done
lemma threadGet_vcg_corres_P:
assumes c: "\<And>x. \<forall>\<sigma>. \<Gamma>\<turnstile> {s. (\<sigma>, s) \<in> rf_sr
\<and> tcb_at' thread \<sigma> \<and> P \<sigma>
\<and> (\<forall>tcb. ko_at' tcb thread \<sigma> \<longrightarrow> (\<exists>tcb'.
x = f tcb \<and> cslift s (tcb_ptr_to_ctcb_ptr thread) = Some tcb'
\<and> ctcb_relation tcb tcb'))} c {s. (\<sigma>, s) \<in> rf_sr \<and> r x (xf s)}"
shows "ccorres r xf P UNIV hs (threadGet f thread) c"
apply (rule ccorres_add_return2)
apply (rule ccorres_guard_imp2)
apply (rule ccorres_pre_threadGet)
apply (rule_tac P = "\<lambda>\<sigma>. \<exists>tcb. ko_at' tcb thread \<sigma> \<and> x = f tcb \<and> P \<sigma>"
and P' = UNIV in ccorres_from_vcg)
apply (simp add: return_def)
apply (rule allI, rule conseqPre)
apply (rule spec [OF c])
apply clarsimp
apply (frule cmap_relation_tcb)
apply (frule (1) cmap_relation_ko_atD)
apply clarsimp
apply (rule conjI)
apply (erule obj_at'_weakenE)
apply simp
apply clarsimp
apply (drule (1) ko_at_obj_congD')
apply simp
apply fastforce
done
lemmas threadGet_vcg_corres = threadGet_vcg_corres_P[where P=\<top>]
lemma threadGet_specs_corres:
assumes spec: "\<forall>s. \<Gamma> \<turnstile> {s} Call g {t. xf t = f' s}"
and mod: "modifies_spec g"
and xf: "\<And>f s. xf (globals_update f s) = xf s"
shows "ccorres r xf (ko_at' ko thread) {s'. r (f ko) (f' s')} hs (threadGet f thread) (Call g)"
apply (rule ccorres_Call_call_for_vcg)
apply (rule ccorres_guard_imp2)
apply (rule ccorres_add_return2)
apply (rule ccorres_pre_threadGet)
apply (rule_tac P = "\<lambda>s. ko_at' ko thread s \<and> x = f ko" in ccorres_from_vcg [where P' = "{s'. r (f ko) (f' s')}"])
apply (rule allI)
apply (rule HoarePartial.ProcModifyReturnNoAbr [where return' = "\<lambda>s t. t\<lparr> globals := globals s \<rparr>"])
apply (rule HoarePartial.ProcSpecNoAbrupt [OF _ _ spec])
defer
apply vcg
prefer 2
apply (rule mod)
apply (clarsimp simp: mex_def meq_def)
apply (frule obj_at'_weakenE [OF _ TrueI])
apply clarsimp
apply (drule (1) ko_at_obj_congD')
apply simp
apply (clarsimp simp: return_def)
apply (rule conjI)
apply (erule iffD1 [OF rf_sr_upd, rotated -1], simp_all)[1]
apply (simp add: xf)
done
lemma ccorres_exI1:
assumes rl: "\<And>x. ccorres r xf (Q x) (P' x) hs a c"
shows "ccorres r xf (\<lambda>s. (\<exists>x. P x s) \<and> (\<forall>x. P x s \<longrightarrow> Q x s))
{s'. \<forall>x s. (s, s') \<in> rf_sr \<and> P x s \<longrightarrow> s' \<in> P' x} hs a c"
apply (rule ccorresI')
apply clarsimp
apply (drule spec, drule (1) mp)
apply (rule ccorresE [OF rl], assumption+)
apply fastforce
apply assumption
apply assumption
apply fastforce
done
lemma isBlocked_ccorres [corres]:
"ccorres (\<lambda>r r'. r = to_bool r') ret__unsigned_long_'
(tcb_at' thread) (UNIV \<inter> {s. thread_' s = tcb_ptr_to_ctcb_ptr thread}) []
(isBlocked thread) (Call isBlocked_'proc)"
apply (cinit lift: thread_' simp: getThreadState_def)
apply (rule ccorres_pre_threadGet)
apply (rule ccorres_move_c_guard_tcb)
apply (rule ccorres_symb_exec_r)
apply (rule ccorres_cond_weak)
apply (rule ccorres_return_C)
apply simp
apply simp
apply simp
apply (simp add: ccorres_cond_iffs)
apply (rule ccorres_return_C)
apply simp
apply simp
apply simp
apply vcg
apply (rule conseqPre)
apply vcg
apply clarsimp
apply clarsimp
apply (clarsimp simp: to_bool_def true_def false_def typ_heap_simps
ctcb_relation_thread_state_to_tsType split: thread_state.splits)
apply (simp add: "StrictC'_thread_state_defs")+
done
lemma isRunnable_ccorres [corres]:
"ccorres (\<lambda>r r'. r = to_bool r') ret__unsigned_long_'
(tcb_at' thread) (UNIV \<inter> {s. thread_' s = tcb_ptr_to_ctcb_ptr thread}) []
(isRunnable thread) (Call isRunnable_'proc)"
apply (cinit lift: thread_' simp: getThreadState_def)
apply (rule ccorres_move_c_guard_tcb)
apply (rule ccorres_pre_threadGet)
apply (rule ccorres_symb_exec_r)
apply (rule ccorres_cond_weak)
apply (rule ccorres_return_C)
apply (simp)
apply (simp)
apply (simp)
apply (simp add: ccorres_cond_iffs)
apply (rule ccorres_return_C)
apply (simp)
apply (simp)
apply (simp)
apply (vcg)
apply (rule conseqPre)
apply (vcg)
apply (clarsimp)
apply (clarsimp)
apply (clarsimp simp: to_bool_def true_def false_def typ_heap_simps
ctcb_relation_thread_state_to_tsType split: thread_state.splits)
apply (simp add: "StrictC'_thread_state_defs")+
done
lemma tcb_queue_relation_update_head:
fixes getNext_update :: "(tcb_C ptr \<Rightarrow> tcb_C ptr) \<Rightarrow> tcb_C \<Rightarrow> tcb_C" and
getPrev_update :: "(tcb_C ptr \<Rightarrow> tcb_C ptr) \<Rightarrow> tcb_C \<Rightarrow> tcb_C"
assumes qr: "tcb_queue_relation getNext getPrev mp queue NULL qhead"
and qh': "qhead' \<notin> tcb_ptr_to_ctcb_ptr ` set queue"
and cs_tcb: "mp qhead' = Some tcb"
and valid_ep: "\<forall>t\<in>set queue. tcb_at' t s" "distinct queue"
and qhN: "qhead' \<noteq> NULL"
and fgN: "fg_cons getNext (getNext_update \<circ> (\<lambda>x _. x))"
and fgP: "fg_cons getPrev (getPrev_update \<circ> (\<lambda>x _. x))"
and npu: "\<And>f t. getNext (getPrev_update f t) = getNext t"
and pnu: "\<And>f t. getPrev (getNext_update f t) = getPrev t"
shows "tcb_queue_relation getNext getPrev
(upd_unless_null qhead (getPrev_update (\<lambda>_. qhead') (the (mp qhead)))
(mp(qhead' := Some (getPrev_update (\<lambda>_. NULL) (getNext_update (\<lambda>_. qhead) tcb)))))
(ctcb_ptr_to_tcb_ptr qhead' # queue) NULL qhead'"
using qr qh' cs_tcb valid_ep qhN
apply (subgoal_tac "qhead \<noteq> qhead'")
apply (clarsimp simp: pnu upd_unless_null_def fg_consD1 [OF fgN] fg_consD1 [OF fgP] pnu npu)
apply (cases queue)
apply simp
apply (frule (2) tcb_queue_relation_next_not_NULL)
apply simp
apply (clarsimp simp: fg_consD1 [OF fgN] fg_consD1 [OF fgP] pnu npu)
apply (subst tcb_queue_relation_cong [OF refl refl refl, where mp' = mp])
apply (clarsimp simp: inj_eq)
apply (intro impI conjI)
apply (frule_tac x = x in imageI [where f = tcb_ptr_to_ctcb_ptr])
apply simp
apply simp
apply simp
apply clarsimp
apply (cases queue)
apply simp
apply simp
done
lemma tcbSchedEnqueue_update:
assumes sr: "sched_queue_relation' mp queue qhead qend"
and qh': "qhead' \<notin> tcb_ptr_to_ctcb_ptr ` set queue"
and cs_tcb: "mp qhead' = Some tcb"
and valid_ep: "\<forall>t\<in>set queue. tcb_at' t s" "distinct queue"
and qhN: "qhead' \<noteq> NULL"
shows
"sched_queue_relation'
(upd_unless_null qhead (tcbSchedPrev_C_update (\<lambda>_. qhead') (the (mp qhead)))
(mp(qhead' \<mapsto> tcb\<lparr>tcbSchedNext_C := qhead, tcbSchedPrev_C := NULL\<rparr>)))
(ctcb_ptr_to_tcb_ptr qhead' # queue) qhead' (if qend = NULL then qhead' else qend)"
using sr qh' cs_tcb valid_ep qhN
apply -
apply (erule tcb_queue_relationE')
apply (rule tcb_queue_relationI')
apply (erule (5) tcb_queue_relation_update_head
[where getNext_update = tcbSchedNext_C_update and getPrev_update = tcbSchedPrev_C_update], simp_all)[1]
apply simp
apply (intro impI)
apply (erule (1) tcb_queue_relation_not_NULL')
apply simp
done
lemma tcb_ptr_to_ctcb_ptr_imageD:
"x \<in> tcb_ptr_to_ctcb_ptr ` S \<Longrightarrow> ctcb_ptr_to_tcb_ptr x \<in> S"
apply (erule imageE)
apply simp
done
lemma ctcb_ptr_to_tcb_ptr_imageI:
"ctcb_ptr_to_tcb_ptr x \<in> S \<Longrightarrow> x \<in> tcb_ptr_to_ctcb_ptr ` S"
apply (drule imageI [where f = tcb_ptr_to_ctcb_ptr])
apply simp
done
lemma tcb_queue'_head_end_NULL:
assumes qr: "tcb_queue_relation' getNext getPrev mp queue qhead qend"
and tat: "\<forall>t\<in>set queue. tcb_at' t s"
shows "(qend = NULL) = (qhead = NULL)"
using qr tat
apply -
apply (erule tcb_queue_relationE')
apply (simp add: tcb_queue_head_empty_iff)
apply (rule impI)
apply (rule tcb_at_not_NULL)
apply (erule bspec)
apply simp
done
lemma tcb_queue_relation_qhead_mem:
"\<lbrakk> tcb_queue_relation getNext getPrev mp queue NULL qhead;
(\<forall>tcb\<in>set queue. tcb_at' tcb t) \<rbrakk>
\<Longrightarrow> qhead \<noteq> NULL \<longrightarrow> ctcb_ptr_to_tcb_ptr qhead \<in> set queue"
by (clarsimp simp: tcb_queue_head_empty_iff tcb_queue_relation_head_hd)
lemma tcb_queue_relation_qhead_valid:
"\<lbrakk> tcb_queue_relation getNext getPrev (cslift s') queue NULL qhead;
(s, s') \<in> rf_sr; (\<forall>tcb\<in>set queue. tcb_at' tcb s) \<rbrakk>
\<Longrightarrow> qhead \<noteq> NULL \<longrightarrow> s' \<Turnstile>\<^sub>c qhead"
apply (frule (1) tcb_queue_relation_qhead_mem)
apply clarsimp
apply(drule (3) tcb_queue_memberD)
apply (simp add: h_t_valid_clift_Some_iff)
done
lemmas tcb_queue_relation_qhead_mem' = tcb_queue_relation_qhead_mem [OF tcb_queue_relation'_queue_rel]
lemmas tcb_queue_relation_qhead_valid' = tcb_queue_relation_qhead_valid [OF tcb_queue_relation'_queue_rel]
lemma valid_queues_valid_q:
"valid_queues s \<Longrightarrow> (\<forall>tcb\<in>set (ksReadyQueues s (qdom, prio)). tcb_at' tcb s) \<and> distinct (ksReadyQueues s (qdom, prio))"
apply (clarsimp simp: valid_queues_def)
apply (drule spec [where x = qdom])
apply (drule spec [where x = prio])
apply clarsimp
apply (drule (1) bspec, erule obj_at'_weakenE)
apply simp
done
lemma invs_valid_q:
"invs' s \<Longrightarrow> (\<forall>tcb\<in>set (ksReadyQueues s (qdom, prio)). tcb_at' tcb s) \<and> distinct (ksReadyQueues s (qdom, prio))"
apply (rule valid_queues_valid_q)
apply (clarsimp simp: invs'_def valid_state'_def)
done
lemma tcbQueued_not_in_queues:
assumes vq: "valid_queues s"
and objat: "obj_at' (Not \<circ> tcbQueued) thread s"
shows "thread \<notin> set (ksReadyQueues s (d, p))"
using vq objat
apply -
apply clarsimp
apply (drule (1) valid_queues_obj_at'D)
apply (erule obj_atE')+
apply (clarsimp simp: inQ_def)
done
declare unat_ucast_8_32[simp]
lemma rf_sr_sched_queue_relation:
"\<lbrakk> (s, s') \<in> rf_sr; d \<le> ucast maxDom; p \<le> ucast maxPrio \<rbrakk>
\<Longrightarrow> sched_queue_relation' (cslift s') (ksReadyQueues s (d, p))
(head_C (index (ksReadyQueues_' (globals s'))
(cready_queues_index_to_C d p)))
(end_C (index (ksReadyQueues_' (globals s'))
(cready_queues_index_to_C d p)))"
unfolding rf_sr_def cstate_relation_def cready_queues_relation_def
apply (clarsimp simp: Let_def seL4_MinPrio_def minDom_def)
done
lemma ready_queue_not_in:
assumes vq: "valid_queues s"
and inq: "t \<in> set (ksReadyQueues s (d, p))"
and neq: "d \<noteq> d' \<or> p \<noteq> p'"
shows "t \<notin> set (ksReadyQueues s (d', p'))"
proof
assume "t \<in> set (ksReadyQueues s (d', p'))"
hence "obj_at' (inQ d' p') t s" using vq by (rule valid_queues_obj_at'D)
moreover have "obj_at' (inQ d p) t s" using inq vq by (rule valid_queues_obj_at'D)
ultimately show False using neq
by (clarsimp elim!: obj_atE' simp: inQ_def)
qed
lemma ctcb_relation_unat_prio_eq:
"ctcb_relation tcb tcb' \<Longrightarrow> unat (tcbPriority tcb) = unat (tcbPriority_C tcb')"
apply (clarsimp simp: ctcb_relation_def)
apply (erule_tac t = "tcbPriority_C tcb'" in subst)
apply simp
done
lemma ctcb_relation_unat_dom_eq:
"ctcb_relation tcb tcb' \<Longrightarrow> unat (tcbDomain tcb) = unat (tcbDomain_C tcb')"
apply (clarsimp simp: ctcb_relation_def)
apply (erule_tac t = "tcbDomain_C tcb'" in subst)
apply simp
done
lemma threadSet_queued_ccorres [corres]:
shows "ccorres dc xfdc (tcb_at' thread)
{s. v_' s = from_bool v \<and> thread_state_ptr_' s = Ptr &(tcb_ptr_to_ctcb_ptr thread\<rightarrow>[''tcbState_C''])} []
(threadSet (tcbQueued_update (\<lambda>_. v)) thread)
(Call thread_state_ptr_set_tcbQueued_'proc)"
apply (rule threadSet_corres_lemma)
apply (rule thread_state_ptr_set_tcbQueued_spec)
apply (rule thread_state_ptr_set_tcbQueued_modifies)
apply clarsimp
apply (frule (1) obj_at_cslift_tcb)
apply clarsimp
apply (rule rf_sr_tcb_update_no_queue, assumption+, simp_all)
apply (rule ball_tcb_cte_casesI, simp_all)
apply (simp add: ctcb_relation_def cthread_state_relation_def)
apply (case_tac "tcbState ko", simp_all add: WordLemmaBucket.from_bool_mask_simp)[1]
apply (frule (1) obj_at_cslift_tcb)
apply (clarsimp simp: typ_heap_simps)
done
lemma ccorres_pre_getQueue:
assumes cc: "\<And>queue. ccorres r xf (P queue) (P' queue) hs (f queue) c"
shows "ccorres r xf (\<lambda>s. P (ksReadyQueues s (d, p)) s \<and> d \<le> maxDomain \<and> p \<le> maxPriority)
{s'. \<forall>queue. (let cqueue = index (ksReadyQueues_' (globals s'))
(cready_queues_index_to_C d p) in
sched_queue_relation' (cslift s') queue (head_C cqueue) (end_C cqueue)) \<longrightarrow> s' \<in> P' queue}
hs (getQueue d p >>= (\<lambda>queue. f queue)) c"
apply (rule ccorres_guard_imp2)
apply (rule ccorres_symb_exec_l2)
defer
defer
apply (rule gq_sp)
defer
apply (rule ccorres_guard_imp)
apply (rule cc)
apply clarsimp
apply assumption
apply assumption
apply (clarsimp simp: getQueue_def gets_exs_valid)
apply clarsimp
apply (drule spec, erule mp)
apply (simp add: Let_def)
apply (erule rf_sr_sched_queue_relation)
apply (simp add: maxDom_to_H maxPrio_to_H)+
done
(* FIXME: move *)
lemma threadGet_wp:
"\<lbrace>\<lambda>s. \<forall>tcb. ko_at' tcb thread s \<longrightarrow> P (f tcb) s\<rbrace> threadGet f thread \<lbrace>P\<rbrace>"
apply (rule hoare_post_imp [OF _ tg_sp'])
apply clarsimp
apply (frule obj_at_ko_at')
apply (clarsimp elim: obj_atE')
done
lemma state_relation_queue_update_helper':
"\<lbrakk> (s, s') \<in> rf_sr;
(\<forall>d p. (\<forall>t\<in>set (ksReadyQueues s (d, p)). obj_at' (inQ d p) t s)
\<and> distinct (ksReadyQueues s (d, p)));
globals t = ksReadyQueues_'_update
(\<lambda>_. Arrays.update (ksReadyQueues_' (globals s')) prio' q')
(t_hrs_'_update f (globals s'));
sched_queue_relation' (cslift t) q (head_C q') (end_C q');
cslift t |` ( - tcb_ptr_to_ctcb_ptr ` S )
= cslift s' |` ( - tcb_ptr_to_ctcb_ptr ` S );
option_map tcb_null_sched_ptrs \<circ> cslift t
= option_map tcb_null_sched_ptrs \<circ> cslift s';
cslift_all_but_tcb_C t s';
hrs_htd (t_hrs_' (globals t)) = hrs_htd (t_hrs_' (globals s'));
prio' = cready_queues_index_to_C qdom prio;
\<forall>x \<in> S. obj_at' (inQ qdom prio) x s
\<or> (obj_at' (\<lambda>tcb. tcbPriority tcb = prio) x s
\<and> obj_at' (\<lambda>tcb. tcbDomain tcb = qdom) x s)
\<or> (tcb_at' x s \<and> (\<forall>d' p'. (d' \<noteq> qdom \<or> p' \<noteq> prio)
\<longrightarrow> x \<notin> set (ksReadyQueues s (d', p'))));
S \<noteq> {}; qdom \<le> ucast maxDom; prio \<le> ucast maxPrio \<rbrakk>
\<Longrightarrow> (s \<lparr>ksReadyQueues := (ksReadyQueues s)((qdom, prio) := q)\<rparr>, t) \<in> rf_sr"
apply (subst(asm) disj_imp_rhs)
apply (subst obj_at'_and[symmetric])
apply (rule disjI1, erule obj_at'_weakenE, simp add: inQ_def)
apply (subst(asm) disj_imp_rhs)
apply (subst(asm) obj_at'_and[symmetric])
apply (rule conjI, erule obj_at'_weakenE, simp)
apply (rule allI, rule allI)
apply (drule_tac x=d' in spec)
apply (drule_tac x=p' in spec)
apply clarsimp
apply (drule(1) bspec)
apply (clarsimp simp: inQ_def obj_at'_def)
apply (clarsimp simp: rf_sr_def cstate_relation_def Let_def)
apply (intro conjI)
-- "cpspace_relation"
apply (erule nonemptyE, drule(1) bspec)
apply (clarsimp simp: cpspace_relation_def)
apply (drule obj_at_ko_at', clarsimp)
apply (rule cmap_relationE1, assumption,
erule ko_at_projectKO_opt)
apply (frule null_sched_queue)
apply (frule null_sched_epD)
apply (intro conjI)
-- "tcb relation"
apply (drule ctcb_relation_null_queue_ptrs,
simp_all)[1]
-- "endpoint relation"
apply (erule iffD1 [OF cmap_relation_cong, OF refl refl, rotated -1])
apply simp
apply (erule cendpoint_relation_upd_tcb_no_queues, simp+)
-- "aep relation"
apply (erule iffD1 [OF cmap_relation_cong, OF refl refl, rotated -1])
apply simp
apply (erule casync_endpoint_relation_upd_tcb_no_queues, simp+)
-- "ready queues"
apply (simp add: cready_queues_relation_def Let_def
cready_queues_index_to_C_in_range
seL4_MinPrio_def minDom_def)
apply clarsimp
apply (frule cready_queues_index_to_C_distinct, assumption+)
apply (clarsimp simp: cready_queues_index_to_C_in_range all_conj_distrib)
apply (rule iffD1 [OF tcb_queue_relation'_cong[OF refl], rotated -1],
drule spec, drule spec, erule mp, simp+)
apply clarsimp
apply (drule_tac x="tcb_ptr_to_ctcb_ptr x" in fun_cong)+
apply (clarsimp simp: restrict_map_def
split: split_if_asm)
apply (simp_all add: carch_state_relation_def cmachine_state_relation_def
h_t_valid_clift_Some_iff)
done
lemma state_relation_queue_update_helper:
"\<lbrakk> (s, s') \<in> rf_sr; valid_queues s;
globals t = ksReadyQueues_'_update
(\<lambda>_. Arrays.update (ksReadyQueues_' (globals s')) prio' q')
(t_hrs_'_update f (globals s'));
sched_queue_relation' (cslift t) q (head_C q') (end_C q');
cslift t |` ( - tcb_ptr_to_ctcb_ptr ` S )
= cslift s' |` ( - tcb_ptr_to_ctcb_ptr ` S );
option_map tcb_null_sched_ptrs \<circ> cslift t
= option_map tcb_null_sched_ptrs \<circ> cslift s';
cslift_all_but_tcb_C t s';
hrs_htd (t_hrs_' (globals t)) = hrs_htd (t_hrs_' (globals s'));
prio' = cready_queues_index_to_C qdom prio;
\<forall>x \<in> S. obj_at' (inQ qdom prio) x s
\<or> (obj_at' (\<lambda>tcb. tcbPriority tcb = prio) x s
\<and> obj_at' (\<lambda>tcb. tcbDomain tcb = qdom) x s)
\<or> (tcb_at' x s \<and> (\<forall>d' p'. (d' \<noteq> qdom \<or> p' \<noteq> prio)
\<longrightarrow> x \<notin> set (ksReadyQueues s (d', p'))));
S \<noteq> {}; qdom \<le> ucast maxDom; prio \<le> ucast maxPrio \<rbrakk>
\<Longrightarrow> (s \<lparr>ksReadyQueues := (ksReadyQueues s)((qdom, prio) := q)\<rparr>, t) \<in> rf_sr"
apply (subgoal_tac "\<forall>d p. (\<forall>t\<in>set (ksReadyQueues s (d, p)). obj_at' (inQ d p) t s)
\<and> distinct(ksReadyQueues s (d, p))")
apply (erule(12) state_relation_queue_update_helper')
apply (clarsimp simp: valid_queues_def)
apply (drule_tac x=d in spec)
apply (drule_tac x=p in spec)
apply (clarsimp)
apply (drule(1) bspec)
apply (erule obj_at'_weakenE, clarsimp)
done
(* FIXME: move *)
lemma from_bool_vals [simp]:
"from_bool True = scast true"
"from_bool False = scast false"
"scast true \<noteq> scast false"
by (auto simp add: from_bool_def true_def false_def)
(* FIXME: move *)
lemma cmap_relation_no_upd:
"\<lbrakk> cmap_relation a c f rel; a p = Some ko; rel ko v; inj f \<rbrakk> \<Longrightarrow> cmap_relation a (c(f p \<mapsto> v)) f rel"
apply (clarsimp simp: cmap_relation_def)
apply (subgoal_tac "f p \<in> dom c")
prefer 2
apply (drule_tac t="dom c" in sym)
apply fastforce
apply clarsimp
apply (drule (1) injD)
apply simp
done
(* FIXME: move *)
lemma cmap_relation_rel_upd:
"\<lbrakk> cmap_relation a c f rel; \<And>v v'. rel v v' \<Longrightarrow> rel' v v' \<rbrakk> \<Longrightarrow> cmap_relation a c f rel'"
by (simp add: cmap_relation_def)
declare fun_upd_restrict_conv[simp del]
lemmas queue_in_range = of_nat_mono_maybe[OF _ cready_queues_index_to_C_in_range,
where 'a=32, unfolded cready_queues_index_to_C_def numPriorities_def,
simplified, unfolded ucast_nat_def]
of_nat_mono_maybe[OF _ cready_queues_index_to_C_in_range,
where 'a="32 signed", unfolded cready_queues_index_to_C_def numPriorities_def,
simplified, unfolded ucast_nat_def]
lemma cready_queues_index_to_C_def2':
"\<lbrakk> qdom \<le> ucast maxDom; prio \<le> ucast maxPrio \<rbrakk>
\<Longrightarrow> cready_queues_index_to_C qdom prio
= unat (ucast qdom * of_nat numPriorities + ucast prio :: 32 word)"
apply (simp add: cready_queues_index_to_C_def numPriorities_def)
apply (subst unat_add_lem[THEN iffD1])
apply (frule cready_queues_index_to_C_in_range, simp)
apply (simp add: cready_queues_index_to_C_def numPriorities_def)
apply (subst unat_mult_simple)
apply (simp add: word_bits_def maxDom_def)
apply simp
apply (subst unat_mult_simple)
apply (simp add: word_bits_def maxDom_def)
apply (subst (asm) word_le_nat_alt)
apply simp
apply simp
done
lemmas cready_queues_index_to_C_def2
= cready_queues_index_to_C_def2'[simplified maxDom_to_H maxPrio_to_H]
lemma ready_queues_index_spec:
"\<forall>s. \<Gamma> \<turnstile> {s} Call ready_queues_index_'proc
\<lbrace>\<acute>ret__unsigned = (dom___unsigned_' s) * 0x100 + (prio___unsigned_' s)\<rbrace>"
apply vcg
apply clarsimp
done
lemma tcbSchedEnqueue_ccorres:
"ccorres dc xfdc
(valid_queues and tcb_at' t and valid_objs')
(UNIV \<inter> \<lbrace>\<acute>tcb = tcb_ptr_to_ctcb_ptr t\<rbrace>)
[]
(tcbSchedEnqueue t)
(Call tcbSchedEnqueue_'proc)"
apply (cinit lift: tcb_')
apply (rule_tac r'="\<lambda>rv rv'. rv = to_bool rv'"
and xf'="ret__unsigned_long_'" in ccorres_split_nothrow)
apply (rule threadGet_vcg_corres)
apply (rule allI, rule conseqPre, vcg)
apply clarsimp
apply (drule obj_at_ko_at', clarsimp)
apply (drule spec, drule(1) mp, clarsimp)
apply (clarsimp simp: typ_heap_simps ctcb_relation_def)
apply ceqv
apply (simp add: unless_def when_def
del: Collect_const split del: split_if)
apply (rule ccorres_cond[where R=\<top>])
apply (simp add: to_bool_def)
apply (rule ccorres_rhs_assoc)+
apply csymbr
apply csymbr
apply csymbr
apply csymbr
apply (rule_tac r'="\<lambda>rv rv'. rv' = ucast rv"
and xf'="dom_'" in ccorres_split_nothrow)
apply (rule threadGet_vcg_corres)
apply (rule allI, rule conseqPre, vcg)
apply clarsimp
apply (drule obj_at_ko_at', clarsimp)
apply (drule spec, drule(1) mp, clarsimp)
apply (clarsimp simp: typ_heap_simps ctcb_relation_def)
apply ceqv
apply (rule_tac r'="\<lambda>rv rv'. rv' = ucast rv"
and xf'="prio_'" in ccorres_split_nothrow)
apply (rule threadGet_vcg_corres)
apply (rule allI, rule conseqPre, vcg)
apply clarsimp
apply (drule obj_at_ko_at', clarsimp)
apply (drule spec, drule(1) mp, clarsimp)
apply (clarsimp simp: typ_heap_simps ctcb_relation_def)
apply ceqv
apply (rule ccorres_rhs_assoc2)+
apply (simp only: bind_assoc[symmetric])
apply (rule ccorres_split_nothrow_novcg_dc)
prefer 2
apply (rule ccorres_move_c_guard_tcb)
apply (simp only: dc_def[symmetric])
apply ctac
prefer 2
apply wp
apply (rule ccorres_rhs_assoc)+
apply csymbr
apply (rule_tac P="\<lambda>s. valid_queues s \<and> (\<forall>d p. t \<notin> set (ksReadyQueues s (d, p)))
\<and> (\<exists>tcb. ko_at' tcb t s \<and> tcbDomain tcb =rva
\<and> tcbPriority tcb = rvb \<and> valid_tcb' tcb s)"
and P'=UNIV in ccorres_from_vcg)
apply (rule allI, rule conseqPre, vcg)
apply (clarsimp simp: getQueue_def gets_def get_def setQueue_def modify_def
put_def bind_def return_def)
apply (clarsimp simp: queue_in_range valid_tcb'_def maxDom_to_H maxPrio_to_H)
apply (drule (1) obj_at_cslift_tcb)
apply (clarsimp simp: ucast_less[THEN order_less_le_trans])
apply (frule_tac d="tcbDomain tcba" and p="tcbPriority tcba"
in rf_sr_sched_queue_relation)
apply (clarsimp simp: maxDom_to_H)
apply (clarsimp simp: maxPrio_to_H)
apply (frule_tac s=\<sigma> in tcb_queue'_head_end_NULL)
apply (simp add: valid_queues_valid_q)
apply (frule_tac s=\<sigma> and qhead'="tcb_ptr_to_ctcb_ptr t"
in tcbSchedEnqueue_update,
simp_all add: valid_queues_valid_q)[1]
apply (rule notI, drule tcb_ptr_to_ctcb_ptr_imageD)
apply simp
apply (rule tcb_at_not_NULL,
erule obj_at'_weakenE, simp)
apply (rule conjI)
apply (clarsimp simp: typ_heap_simps)
apply (erule(1) state_relation_queue_update_helper
[where S="{t}"],
simp_all add: cready_queues_index_to_C_def2 numPriorities_def
typ_heap_simps maxDom_to_H maxPrio_to_H)[1]
apply (simp add: upd_unless_null_def)
apply (rule ext)
apply (simp add: tcb_null_sched_ptrs_def)
apply (simp add: obj_at'_weakenE[OF _ TrueI])
apply (frule_tac t=\<sigma> in tcb_queue_relation_qhead_mem')
apply (simp add: valid_queues_valid_q)
apply (drule(1) tcb_queue_relation_qhead_valid')
apply (simp add: valid_queues_valid_q)
apply (clarsimp simp: typ_heap_simps h_t_valid_clift_Some_iff numPriorities_def
cready_queues_index_to_C_def2)
apply (erule_tac S="{t, v}" for v in state_relation_queue_update_helper,
simp_all add: cready_queues_index_to_C_def2 numPriorities_def
typ_heap_simps maxDom_to_H maxPrio_to_H)[1]
apply (simp add: upd_unless_null_def)
apply (subst clift_field_update
| simp add: if_Some_helper
split del: split_if cong: if_cong)+
apply (simp split: split_if, intro impI conjI)
apply (drule ctcb_ptr_to_tcb_ptr_imageI)
apply fastforce
apply (simp add: fun_upd_twist)
prefer 3
apply (simp add: obj_at'_weakenE[OF _ TrueI])
apply (rule disjI1, erule(1) valid_queues_obj_at'D)
apply (subst clift_field_update | simp split del: split_if
| simp add: typ_heap_simps if_Some_helper cong: if_cong)+
apply (intro conjI impI ext)
apply (simp add: tcb_null_sched_ptrs_def)
apply (simp add: tcb_null_sched_ptrs_def)
apply (simp add: guard_is_UNIV_def true_def from_bool_def)
apply simp
apply (wp threadGet_wp)
apply vcg
apply simp
apply (wp threadGet_wp)
apply vcg
apply (rule ccorres_return_Skip[unfolded dc_def])
apply simp
apply (wp threadGet_wp)
apply vcg
apply clarsimp
apply (rule conjI)
apply clarsimp
apply (drule(1) valid_queues_obj_at'D)
apply (clarsimp simp: obj_at'_def projectKOs inQ_def)
apply (fastforce simp: valid_objs'_def obj_at'_def ran_def projectKOs
typ_at'_def valid_obj'_def)
done
lemmas tcbSchedDequeue_update
= tcbDequeue_update[where tn=tcbSchedNext_C and tn_update=tcbSchedNext_C_update
and tp=tcbSchedPrev_C and tp_update=tcbSchedPrev_C_update,
simplified]
lemma tcb_queue_relation_prev_next:
"\<lbrakk> tcb_queue_relation tn tp mp queue qprev qhead;
tcbp \<in> set queue; distinct (ctcb_ptr_to_tcb_ptr qprev # queue);
\<forall>t \<in> set queue. tcb_at' t s; qprev \<noteq> tcb_Ptr 0 \<longrightarrow> mp qprev \<noteq> None;
mp (tcb_ptr_to_ctcb_ptr tcbp) = Some tcb \<rbrakk>
\<Longrightarrow> (tn tcb \<noteq> tcb_Ptr 0 \<longrightarrow> tn tcb \<in> tcb_ptr_to_ctcb_ptr ` set queue
\<and> mp (tn tcb) \<noteq> None \<and> tn tcb \<noteq> tcb_ptr_to_ctcb_ptr tcbp)
\<and> (tp tcb \<noteq> tcb_Ptr 0 \<longrightarrow> (tp tcb \<in> tcb_ptr_to_ctcb_ptr ` set queue
\<or> tp tcb = qprev)
\<and> mp (tp tcb) \<noteq> None \<and> tp tcb \<noteq> tcb_ptr_to_ctcb_ptr tcbp)
\<and> (tn tcb \<noteq> tcb_Ptr 0 \<longrightarrow> tn tcb \<noteq> tp tcb)"
apply (induct queue arbitrary: qprev qhead)
apply simp
apply simp
apply (erule disjE)
apply clarsimp
apply (case_tac "queue")
apply clarsimp
apply clarsimp
apply (rule conjI)
apply clarsimp
apply clarsimp
apply (drule_tac f=ctcb_ptr_to_tcb_ptr in arg_cong[where y="tp tcb"], simp)
apply clarsimp
apply fastforce
done
lemma tcb_queue_relation_prev_next':