-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVSpace_C.thy
3320 lines (3109 loc) · 149 KB
/
VSpace_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 VSpace_C
imports TcbAcc_C CSpace_C PSpace_C TcbQueue_C
begin
declare empty_fail_error_bits[simp]
(* FIXME: move *)
lemma empty_fail_findPDForASID[iff]:
"empty_fail (findPDForASID asid)"
apply (simp add: findPDForASID_def liftME_def)
apply (intro empty_fail_bindE, simp_all split: option.split)
apply (simp add: assertE_def split: split_if)
apply (simp add: assertE_def split: split_if)
apply (simp add: empty_fail_getObject)
apply (simp add: assertE_def liftE_bindE checkPDAt_def split: split_if)
done
(* FIXME: move *)
lemma empty_fail_findPDForASIDAssert[iff]:
"empty_fail (findPDForASIDAssert asid)"
apply (simp add: findPDForASIDAssert_def catch_def
checkPDAt_def checkPDUniqueToASID_def
checkPDASIDMapMembership_def)
apply (intro empty_fail_bind, simp_all split: sum.split)
done
lemma mask_AND_less_0:
"\<lbrakk>x && mask n = 0; m \<le> n\<rbrakk> \<Longrightarrow> x && mask m = 0"
apply (case_tac "len_of TYPE('a) \<le> n")
apply (clarsimp simp: ge_mask_eq)
apply (erule is_aligned_AND_less_0)
apply (clarsimp simp: mask_2pm1 two_power_increasing)
done
context kernel_m begin
lemma pageBitsForSize_le:
"pageBitsForSize x \<le> 24"
by (simp add: pageBitsForSize_def split: vmpage_size.splits)
lemma unat_of_nat_pageBitsForSize [simp]:
"unat (of_nat (pageBitsForSize x)::word32) = pageBitsForSize x"
apply (subst unat_of_nat32)
apply (rule order_le_less_trans, rule pageBitsForSize_le)
apply (simp add: word_bits_def)
apply simp
done
lemma checkVPAlignment_ccorres:
"ccorres (\<lambda>a c. if to_bool c then a = Inr () else a = Inl AlignmentError) ret__unsigned_long_'
\<top>
(UNIV \<inter> \<lbrace>sz = gen_framesize_to_H \<acute>sz \<and> \<acute>sz && mask 2 = \<acute>sz\<rbrace> \<inter> \<lbrace>\<acute>w = w\<rbrace>)
[]
(checkVPAlignment sz w)
(Call checkVPAlignment_'proc)"
proof -
note [split del] = split_if
show ?thesis
apply (cinit lift: sz_' w_')
apply (csymbr)
apply clarsimp
apply (rule ccorres_Guard [where A=\<top> and C'=UNIV])
apply (simp split: split_if)
apply (rule conjI)
apply (clarsimp simp: mask_def unlessE_def returnOk_def)
apply (rule ccorres_guard_imp)
apply (rule ccorres_return_C)
apply simp
apply simp
apply simp
apply simp
apply (simp split: split_if add: to_bool_def)
apply (clarsimp simp: mask_def unlessE_def throwError_def split: split_if)
apply (rule ccorres_guard_imp)
apply (rule ccorres_return_C)
apply simp
apply simp
apply simp
apply simp
apply (simp split: split_if add: to_bool_def)
apply (clarsimp split: split_if)
apply (simp add: word_less_nat_alt)
apply (rule order_le_less_trans, rule pageBitsForSize_le)
apply simp
done
qed
declare word_neq_0_conv [simp del]
lemma rf_asidTable:
"\<lbrakk> (\<sigma>, x) \<in> rf_sr; valid_arch_state' \<sigma>; idx \<le> mask asid_high_bits \<rbrakk>
\<Longrightarrow> case armKSASIDTable (ksArchState \<sigma>)
idx of
None \<Rightarrow>
index (armKSASIDTable_' (globals x)) (unat idx) =
NULL
| Some v \<Rightarrow>
index (armKSASIDTable_' (globals x)) (unat idx) = Ptr v \<and>
index (armKSASIDTable_' (globals x)) (unat idx) \<noteq> NULL"
apply (clarsimp simp: rf_sr_def cstate_relation_def Let_def
carch_state_relation_def
array_relation_def)
apply (drule_tac x=idx in spec)+
apply (clarsimp simp: mask_def split: option.split)
apply (drule sym, simp)
apply (simp add: option_to_ptr_def option_to_0_def)
apply (clarsimp simp: invs'_def valid_state'_def valid_arch_state'_def
valid_asid_table'_def ran_def)
done
lemma getKSASIDTable_ccorres_stuff:
"\<lbrakk> invs' \<sigma>; (\<sigma>, x) \<in> rf_sr; idx' = unat idx;
idx < 2 ^ asid_high_bits \<rbrakk>
\<Longrightarrow> case armKSASIDTable (ksArchState \<sigma>)
idx of
None \<Rightarrow>
index (armKSASIDTable_' (globals x))
idx' =
NULL
| Some v \<Rightarrow>
index (armKSASIDTable_' (globals x))
idx' = Ptr v \<and>
index (armKSASIDTable_' (globals x))
idx' \<noteq> NULL"
apply (drule rf_asidTable [where idx=idx])
apply fastforce
apply (simp add: mask_def)
apply (simp add: minus_one_helper3)
apply (clarsimp split: option.splits)
done
lemma asidLowBits_handy_convs:
"sint Kernel_C.asidLowBits = 10"
"Kernel_C.asidLowBits \<noteq> 0x20"
"unat Kernel_C.asidLowBits = asid_low_bits"
by (simp add: Kernel_C.asidLowBits_def asid_low_bits_def)+
lemma rf_sr_armKSASIDTable:
"\<lbrakk> (s, s') \<in> rf_sr; n \<le> 2 ^ asid_high_bits - 1 \<rbrakk>
\<Longrightarrow> index (armKSASIDTable_' (globals s')) (unat n)
= option_to_ptr (armKSASIDTable (ksArchState s) n)"
by (clarsimp simp: rf_sr_def cstate_relation_def Let_def
carch_state_relation_def array_relation_def)
lemma asid_high_bits_word_bits:
"asid_high_bits < word_bits"
by (simp add: asid_high_bits_def word_bits_def)
lemma rf_sr_asid_map_pd_to_hwasids:
"(s, s') \<in> rf_sr \<Longrightarrow>
asid_map_pd_to_hwasids (armKSASIDMap (ksArchState s))
= Option.set \<circ> (pde_stored_asid \<circ>\<^sub>m cslift s' \<circ>\<^sub>m pd_pointer_to_asid_slot)"
by (simp add: rf_sr_def cstate_relation_def Let_def
carch_state_relation_def)
lemma pd_at_asid_cross_over:
"\<lbrakk> pd_at_asid' pd asid s; asid \<le> mask asid_bits;
(s, s') \<in> rf_sr\<rbrakk>
\<Longrightarrow> \<exists>apptr ap pde. index (armKSASIDTable_' (globals s')) (unat (asid >> asid_low_bits))
= (ap_Ptr apptr) \<and> cslift s' (ap_Ptr apptr) = Some (asid_pool_C ap)
\<and> index ap (unat (asid && 2 ^ asid_low_bits - 1)) = pde_Ptr pd
\<and> cslift s' (pde_Ptr (pd + 0x3FC0)) = Some pde
\<and> is_aligned pd pdBits
\<and> (valid_pde_mappings' s \<longrightarrow> pde_get_tag pde = scast pde_pde_invalid)"
apply (clarsimp simp: pd_at_asid'_def)
apply (subgoal_tac "asid >> asid_low_bits \<le> 2 ^ asid_high_bits - 1")
prefer 2
apply (simp add: asid_high_bits_word_bits)
apply (rule shiftr_less_t2n)
apply (simp add: mask_def)
apply (simp add: asid_low_bits_def asid_high_bits_def asid_bits_def)
apply (simp add: rf_sr_armKSASIDTable)
apply (subgoal_tac "ucast (asid_high_bits_of asid) = asid >> asid_low_bits")
prefer 2
apply (simp add: asid_high_bits_of_def ucast_ucast_mask asid_high_bits_def[symmetric])
apply (subst mask_eq_iff_w2p, simp add: asid_high_bits_def word_size)
apply (rule shiftr_less_t2n)
apply (simp add: mask_def, simp add: asid_bits_def asid_low_bits_def asid_high_bits_def)
apply (simp add: option_to_ptr_def option_to_0_def)
apply (rule cmap_relationE1 [OF rf_sr_cpspace_asidpool_relation],
assumption, erule ko_at_projectKO_opt)
apply (clarsimp simp: casid_pool_relation_def array_relation_def
split: asid_pool_C.split_asm)
apply (drule spec, drule sym [OF mp])
apply (rule_tac y=asid in word_and_le1)
apply (clarsimp simp: mask_2pm1[symmetric] option_to_ptr_def option_to_0_def
page_directory_at'_def typ_at_to_obj_at_arches)
apply (drule_tac x="pd_asid_slot" in spec, simp add: pd_asid_slot_def)
apply (drule obj_at_ko_at'[where 'a=pde], clarsimp)
apply (rule cmap_relationE1 [OF rf_sr_cpde_relation],
assumption, erule ko_at_projectKO_opt)
apply (clarsimp simp: valid_pde_mappings'_def)
apply (elim allE, drule(1) mp)
apply (simp add: valid_pde_mapping'_def valid_pde_mapping_offset'_def
pd_asid_slot_def mask_add_aligned)
apply (simp add: mask_def pdBits_def pageBits_def)
apply (clarsimp simp add: cpde_relation_def Let_def)
apply (simp add: pde_lift_def Let_def split: split_if_asm)
done
lemma findPDForASIDAssert_pd_at_wp2:
"\<lbrace>\<lambda>s. \<forall>pd. pd_at_asid' pd asid s
\<and> pd \<notin> ran (option_map snd \<circ> armKSASIDMap (ksArchState s) |` (- {asid}))
\<and> option_map snd (armKSASIDMap (ksArchState s) asid) \<in> {None, Some pd}
\<longrightarrow> P pd s\<rbrace> findPDForASIDAssert asid \<lbrace>P\<rbrace>"
apply (rule hoare_pre)
apply (simp add: findPDForASIDAssert_def const_def
checkPDAt_def checkPDUniqueToASID_def
checkPDASIDMapMembership_def)
apply (wp findPDForASID_pd_at_wp)
apply clarsimp
apply (drule spec, erule mp)
apply clarsimp
apply (clarsimp split: option.split_asm)
done
lemma asid_shiftr_low_bits_less:
"(asid :: word32) \<le> mask asid_bits \<Longrightarrow> asid >> asid_low_bits < 0x100"
apply (rule_tac y="2 ^ 8" in order_less_le_trans)
apply (rule shiftr_less_t2n)
apply (simp add: le_mask_iff_lt_2n[THEN iffD1] asid_bits_def asid_low_bits_def)
apply simp
done
lemma loadHWASID_ccorres:
"ccorres (\<lambda>a b. a = pde_stored_asid b \<and> pde_get_tag b = scast pde_pde_invalid)
ret__struct_pde_C_'
(valid_pde_mappings' and (\<lambda>_. asid \<le> mask asid_bits)) (UNIV \<inter> {s. asid_' s = asid}) []
(loadHWASID asid) (Call loadHWASID_'proc)"
apply (rule ccorres_gen_asm)
apply (cinit lift: asid_')
apply (rule ccorres_Guard_Seq)+
apply (rule ccorres_symb_exec_l [OF _ _ _ empty_fail_gets])
apply (rule ccorres_symb_exec_l [OF _ _ _ empty_fail_findPDForASIDAssert])
apply (rename_tac pd)
apply (rule_tac P="\<lambda>s. pd_at_asid' pd asid s \<and> rv = armKSASIDMap (ksArchState s)
\<and> pd \<notin> ran (option_map snd o armKSASIDMap (ksArchState s)
|` (- {asid}))
\<and> option_map snd (armKSASIDMap (ksArchState s) asid) \<in> {None, Some pd}
\<and> valid_pde_mappings' s"
in ccorres_from_vcg_throws[where P'=UNIV])
apply (rule allI, rule conseqPre, vcg)
apply (clarsimp simp: return_def)
apply (frule(2) pd_at_asid_cross_over)
apply (clarsimp simp: asidLowBits_handy_convs word_sless_def word_sle_def)
apply (clarsimp simp: typ_heap_simps order_le_less_trans[OF word_and_le1]
arg_cong[where f="\<lambda>x. 2 ^ x", OF meta_eq_to_obj_eq, OF asid_low_bits_def])
apply (clarsimp split: option.split)
apply (frule_tac x=pd in fun_cong [OF rf_sr_asid_map_pd_to_hwasids])
apply (simp add: asid_map_pd_to_hwasids_def
pd_pointer_to_asid_slot_def)
apply (intro conjI allI impI)
apply (rule ccontr, clarsimp)
apply (drule singleton_eqD)
apply (clarsimp elim!: ranE)
apply (erule notE, rule_tac a=xa in ranI)
apply (simp add: restrict_map_def split: split_if)
apply clarsimp
apply clarsimp
apply (drule_tac x=a in eqset_imp_iff)
apply (drule iffD1)
apply fastforce
apply simp
apply wp[1]
apply (rule findPDForASIDAssert_pd_at_wp2)
apply wp
apply (clarsimp simp: asidLowBits_handy_convs word_sless_def word_sle_def
Collect_const_mem asid_shiftr_low_bits_less)
done
lemma array_relation_update:
"\<lbrakk> array_relation R bound table (arr :: 'a['b :: finite]);
x' = unat (x :: ('td :: len) word); R v v';
unat bound < card (UNIV :: 'b set) \<rbrakk>
\<Longrightarrow> array_relation R bound (table (x := v))
(Arrays.update arr x' v')"
by (simp add: array_relation_def word_le_nat_alt split: split_if)
lemma asid_map_pd_to_hwasids_update:
"\<lbrakk> pd \<notin> ran (option_map snd \<circ> m |` (- {asid}));
\<forall>hw_asid pd'. m asid = Some (hw_asid, pd') \<longrightarrow> pd' = pd \<rbrakk> \<Longrightarrow>
asid_map_pd_to_hwasids (m (asid \<mapsto> (hw_asid, pd)))
= (asid_map_pd_to_hwasids m) (pd := {hw_asid})"
apply (rule ext, rule set_eqI)
apply (simp add: asid_map_pd_to_hwasids_def split: split_if)
apply (intro conjI impI)
apply (rule iffI)
apply (rule ccontr, clarsimp elim!: ranE split: split_if_asm)
apply (erule notE, rule ranI, simp add: restrict_map_def)
apply (subst if_P, assumption)
apply simp
apply (fastforce split: split_if)
apply (simp add: ran_def split: split_if)
apply (rule iffI)
apply fastforce
apply (erule exEI)
apply clarsimp
done
lemma storeHWASID_ccorres:
"ccorres dc xfdc (valid_pde_mappings' and (\<lambda>_. asid \<le> mask asid_bits))
(UNIV \<inter> {s. asid_' s = asid} \<inter> {s. hw_asid_' s = ucast hw_asid}) []
(storeHWASID asid hw_asid) (Call storeHWASID_'proc)"
apply (rule ccorres_gen_asm)
apply (cinit lift: asid_' hw_asid_')
apply (rule ccorres_Guard_Seq)+
apply (rule ccorres_symb_exec_l [OF _ _ _ empty_fail_findPDForASIDAssert])
apply (rename_tac pd)
apply (rule_tac P="\<lambda>s. pd_at_asid' pd asid s
\<and> pd \<notin> ran (option_map snd o armKSASIDMap (ksArchState s)
|` (- {asid}))
\<and> option_map snd (armKSASIDMap (ksArchState s) asid) \<in> {None, Some pd}
\<and> valid_pde_mappings' s"
in ccorres_from_vcg[where P'=UNIV])
apply (rule allI, rule conseqPre, vcg)
apply (clarsimp simp: Collect_const_mem word_sle_def word_sless_def
asidLowBits_handy_convs simpler_gets_def
simpler_modify_def bind_def)
apply (frule(2) pd_at_asid_cross_over)
apply (clarsimp simp: typ_heap_simps)
apply (clarsimp simp: rf_sr_def cstate_relation_def Let_def
cpspace_relation_def)
apply (clarsimp simp: typ_heap_simps cmachine_state_relation_def
carch_state_relation_def pd_at_asid'_def
fun_upd_def[symmetric] carch_globals_def
order_le_less_trans[OF word_and_le1]
arg_cong[where f="\<lambda>x. 2 ^ x", OF meta_eq_to_obj_eq, OF asid_low_bits_def])
apply (subgoal_tac "ucast hw_asid <s (256 :: sword32) \<and> ucast hw_asid < (256 :: sword32)
\<and> (0 :: sword32) <=s ucast hw_asid")
prefer 2
apply (simp add: word_sless_msb_less ucast_less[THEN order_less_le_trans]
word_0_sle_from_less)
apply (simp add: word_sless_def word_sle_def cslift_ptr_safe)
apply (intro conjI)
apply (erule iffD1 [OF cmap_relation_cong, rotated -1], simp_all)[1]
apply (simp split: split_if_asm)
apply (clarsimp simp: cpde_relation_def Let_def
pde_lift_pde_invalid
cong: Hardware_H.pde.case_cong)
apply (erule array_relation_update)
apply simp
apply (simp add: option_to_0_def)
apply simp
apply (subst asid_map_pd_to_hwasids_update, assumption)
apply clarsimp
apply (rule ext, simp add: pd_pointer_to_asid_slot_def map_comp_def split: split_if)
apply (clarsimp simp: pde_stored_asid_def true_def mask_def[where n="Suc 0"])
apply (subst less_mask_eq)
apply (rule order_less_le_trans, rule ucast_less)
apply simp+
apply (subst ucast_up_ucast_id)
apply (simp add: is_up_def source_size_def target_size_def word_size)
apply simp
apply wp[1]
apply (rule findPDForASIDAssert_pd_at_wp2)
apply (clarsimp simp: asidLowBits_handy_convs word_sle_def word_sless_def
Collect_const_mem asid_shiftr_low_bits_less)
done
lemma invalidateHWASIDEntry_ccorres:
"hwasid' = unat hwasid \<Longrightarrow>
ccorres dc xfdc \<top> UNIV
[] (invalidateHWASIDEntry hwasid)
(Basic (\<lambda>s. globals_update (
armKSHWASIDTable_'_update
(\<lambda>_. Arrays.update (armKSHWASIDTable_' (globals s))
hwasid' (scast asidInvalid))) s))"
apply (clarsimp simp: invalidateHWASIDEntry_def)
apply (rule ccorres_from_vcg)
apply (rule allI, rule conseqPre, vcg)
apply (clarsimp simp: bind_def simpler_gets_def
simpler_modify_def)
apply (clarsimp simp: rf_sr_def cstate_relation_def
Let_def)
apply (clarsimp simp: carch_state_relation_def carch_globals_def
cmachine_state_relation_def)
apply (simp add: array_relation_def split: split_if, erule allEI)
apply (clarsimp simp: word_le_nat_alt)
apply (simp add: option_to_0_def asidInvalid_def)
done
lemma asid_map_pd_to_hwasids_clear:
"\<lbrakk> pd \<notin> ran (option_map snd \<circ> m |` (- {asid}));
\<forall>hw_asid pd'. m asid = Some (hw_asid, pd') \<longrightarrow> pd' = pd \<rbrakk> \<Longrightarrow>
asid_map_pd_to_hwasids (m (asid := None))
= (asid_map_pd_to_hwasids m) (pd := {})"
apply (rule ext, rule set_eqI)
apply (simp add: asid_map_pd_to_hwasids_def split: split_if)
apply (intro conjI impI)
apply (clarsimp elim!: ranE split: split_if_asm)
apply (erule notE, rule ranI, simp add: restrict_map_def)
apply (subst if_P, assumption)
apply simp
apply (simp add: ran_def split: split_if)
apply (rule iffI)
apply fastforce
apply (erule exEI)
apply clarsimp
done
lemma invalidateASID_ccorres:
"ccorres dc xfdc (valid_pde_mappings' and (\<lambda>_. asid \<le> mask asid_bits))
(UNIV \<inter> {s. asid_' s = asid}) []
(invalidateASID asid) (Call invalidateASID_'proc)"
apply (rule ccorres_gen_asm)
apply (cinit lift: asid_')
apply (rule ccorres_Guard_Seq)+
apply (rule ccorres_symb_exec_l [OF _ _ _ empty_fail_findPDForASIDAssert])
apply (rename_tac pd)
apply (rule_tac P="\<lambda>s. pd_at_asid' pd asid s \<and> valid_pde_mappings' s
\<and> pd \<notin> ran (option_map snd o armKSASIDMap (ksArchState s)
|` (- {asid}))
\<and> option_map snd (armKSASIDMap (ksArchState s) asid) \<in> {None, Some pd}"
in ccorres_from_vcg[where P'=UNIV])
apply (rule allI, rule conseqPre, vcg)
apply (clarsimp simp: Collect_const_mem word_sle_def word_sless_def
asidLowBits_handy_convs simpler_gets_def
simpler_modify_def bind_def)
apply (frule(2) pd_at_asid_cross_over)
apply (clarsimp simp: typ_heap_simps)
apply (clarsimp simp: rf_sr_def cstate_relation_def Let_def
cpspace_relation_def)
apply (clarsimp simp: typ_heap_simps cmachine_state_relation_def
carch_state_relation_def pd_at_asid'_def carch_globals_def
fun_upd_def[symmetric] order_le_less_trans[OF word_and_le1]
arg_cong[where f="\<lambda>x. 2 ^ x", OF meta_eq_to_obj_eq, OF asid_low_bits_def])
apply (intro conjI)
apply (erule iffD1 [OF cmap_relation_cong, rotated -1], simp_all)[1]
apply (simp split: split_if_asm)
apply (clarsimp simp: cpde_relation_def Let_def
pde_lift_pde_invalid
cong: Hardware_H.pde.case_cong)
apply (subst asid_map_pd_to_hwasids_clear, assumption)
apply clarsimp
apply (rule ext, simp add: pd_pointer_to_asid_slot_def map_comp_def split: split_if)
apply (clarsimp simp: pde_stored_asid_def false_def mask_def[where n="Suc 0"])
apply wp[1]
apply (wp findPDForASIDAssert_pd_at_wp2)
apply (clarsimp simp: asidLowBits_handy_convs word_sle_def word_sless_def
asid_shiftr_low_bits_less)
done
definition
"vm_fault_type_from_H fault \<equiv>
case fault of
vmfault_type.ARMDataAbort \<Rightarrow> (scast ARMDataAbort :: word32)
| vmfault_type.ARMPrefetchAbort \<Rightarrow> scast ARMPrefetchAbort"
lemma mask_32_id [simp]:
"(x::word32) && mask 32 = x"
using uint_lt2p [of x] by (simp add: mask_eq_iff)
lemma handleVMFault_ccorres:
"ccorres ((\<lambda>a ex v. ex = scast EXCEPTION_FAULT \<and> (\<exists>vf.
a = VMFault (fault_vm_fault_CL.address_CL vf) [instructionFault_CL vf, FSR_CL vf] \<and>
errfault v = Some (Fault_vm_fault vf))) \<currency>
(\<lambda>_. \<bottom>))
(liftxf errstate id (K ()) ret__unsigned_long_')
\<top>
(UNIV \<inter> \<lbrace>\<acute>thread = tcb_ptr_to_ctcb_ptr thread\<rbrace> \<inter> \<lbrace>\<acute>vm_faultType = vm_fault_type_from_H vm_fault\<rbrace>)
[]
(handleVMFault thread vm_fault)
(Call handleVMFault_'proc)"
apply (cinit lift: vm_faultType_')
apply (unfold ArchVSpace_H.handleVMFault_def)
apply wpc
apply (simp add: vm_fault_type_from_H_def Kernel_C.ARMDataAbort_def Kernel_C.ARMPrefetchAbort_def)
apply (simp add: ccorres_cond_univ_iff)
apply (rule ccorres_rhs_assoc)+
apply csymbr
apply csymbr
apply (ctac (no_vcg) add: getFAR_ccorres pre: ccorres_liftE_Seq)
apply (ctac (no_vcg) add: getDFSR_ccorres pre: ccorres_liftE_Seq)
apply clarsimp
apply (rule ccorres_from_vcg_throws [where P=\<top> and P'=UNIV])
apply (clarsimp simp add: throwError_def throw_def return_def)
apply (rule conseqPre)
apply vcg
apply (clarsimp simp: errstate_def)
apply (clarsimp simp: EXCEPTION_FAULT_def EXCEPTION_NONE_def)
apply (simp add: fault_vm_fault_lift false_def)
apply wp
apply (simp add: vm_fault_type_from_H_def Kernel_C.ARMDataAbort_def Kernel_C.ARMPrefetchAbort_def)
apply (simp add: ccorres_cond_univ_iff ccorres_cond_empty_iff)
apply (rule ccorres_rhs_assoc)+
apply csymbr
apply csymbr
apply (ctac (no_vcg) pre: ccorres_liftE_Seq)
apply (ctac (no_vcg) add: getIFSR_ccorres pre: ccorres_liftE_Seq)
apply (rule ccorres_from_vcg_throws [where P=\<top> and P'=UNIV])
apply (clarsimp simp add: throwError_def throw_def return_def)
apply (rule conseqPre)
apply vcg
apply (clarsimp simp: errstate_def)
apply (clarsimp simp: EXCEPTION_FAULT_def EXCEPTION_NONE_def)
apply (simp add: fault_vm_fault_lift true_def mask_def)
apply wp
apply simp
done
lemma unat_asidLowBits [simp]:
"unat Kernel_C.asidLowBits = asidLowBits"
by (simp add: asidLowBits_def Kernel_C.asidLowBits_def asid_low_bits_def)
lemma rf_sr_asidTable_None:
"\<lbrakk> (\<sigma>, x) \<in> rf_sr; asid && mask asid_bits = asid; valid_arch_state' \<sigma> \<rbrakk> \<Longrightarrow>
(index (armKSASIDTable_' (globals x)) (unat (asid >> asid_low_bits)) = ap_Ptr 0) =
(armKSASIDTable (ksArchState \<sigma>) (ucast (asid_high_bits_of asid)) = None)"
apply (simp add: asid_high_bits_of_def ucast_ucast_mask)
apply (subgoal_tac "(asid >> asid_low_bits) && mask 8 = asid >> asid_low_bits")
prefer 2
apply (rule word_eqI)
apply (subst (asm) bang_eq)
apply (simp add: word_size nth_shiftr asid_bits_def asid_low_bits_def)
apply (case_tac "n < 8", simp)
apply (clarsimp simp: linorder_not_less)
apply (erule_tac x="n+10" in allE)
apply simp
apply simp
apply (clarsimp simp: rf_sr_def cstate_relation_def Let_def carch_state_relation_def)
apply (simp add: array_relation_def option_to_0_def)
apply (erule_tac x="asid >> asid_low_bits" in allE)
apply (erule impE)
prefer 2
apply (drule sym [where t="index a b", standard])
apply (simp add: option_to_0_def option_to_ptr_def split: option.splits)
apply (clarsimp simp: valid_arch_state'_def valid_asid_table'_def ran_def)
apply (simp add: and_mask_eq_iff_le_mask)
apply (simp add: asid_high_bits_def mask_def)
done
lemma leq_asid_bits_shift:
"x \<le> mask asid_bits \<Longrightarrow> (x::word32) >> asid_low_bits \<le> mask asid_high_bits"
apply (rule word_leI)
apply (simp add: nth_shiftr word_size)
apply (rule ccontr)
apply (clarsimp simp: linorder_not_less asid_high_bits_def asid_low_bits_def)
apply (simp add: mask_def)
apply (simp add: upper_bits_unset_is_l2p [symmetric])
apply (simp add: asid_bits_def word_bits_def)
apply (erule_tac x="n+10" in allE)
apply (simp add: linorder_not_less)
apply (drule test_bit_size)
apply (simp add: word_size)
done
lemma ucast_asid_high_bits_is_shift:
"asid \<le> mask asid_bits \<Longrightarrow> ucast (asid_high_bits_of asid) = (asid >> asid_low_bits)"
apply (simp add: mask_def upper_bits_unset_is_l2p [symmetric])
apply (simp add: asid_high_bits_of_def)
apply (rule word_eqI)
apply (simp add: word_size nth_shiftr nth_ucast asid_low_bits_def asid_bits_def word_bits_def)
apply (erule_tac x="n+10" in allE)
apply simp
apply (case_tac "n < 8", simp)
apply (simp add: linorder_not_less)
apply (rule notI)
apply (frule test_bit_size)
apply (simp add: word_size)
done
lemma cap_small_frame_cap_get_capFMappedASID_spec:
"\<forall>s. \<Gamma>\<turnstile> \<lbrace>s. cap_get_tag \<acute>cap = scast cap_small_frame_cap\<rbrace>
Call cap_small_frame_cap_get_capFMappedASID_'proc
\<lbrace>\<acute>ret__unsigned_long =
(cap_small_frame_cap_CL.capFMappedASIDHigh_CL (cap_small_frame_cap_lift \<^bsup>s\<^esup>cap) << asidLowBits)
+ (cap_small_frame_cap_CL.capFMappedASIDLow_CL (cap_small_frame_cap_lift \<^bsup>s\<^esup>cap))\<rbrace>"
apply vcg
apply (clarsimp simp: asidLowBits_def Kernel_C.asidLowBits_def word_sle_def
asid_low_bits_def)
done
lemma cap_frame_cap_get_capFMappedASID_spec:
"\<forall>s. \<Gamma>\<turnstile> \<lbrace>s. cap_get_tag \<acute>cap = scast cap_frame_cap\<rbrace>
Call cap_frame_cap_get_capFMappedASID_'proc
\<lbrace>\<acute>ret__unsigned_long =
(cap_frame_cap_CL.capFMappedASIDHigh_CL (cap_frame_cap_lift \<^bsup>s\<^esup>cap) << asidLowBits)
+ (cap_frame_cap_CL.capFMappedASIDLow_CL (cap_frame_cap_lift \<^bsup>s\<^esup>cap))\<rbrace>"
apply vcg
apply (clarsimp simp: asidLowBits_def Kernel_C.asidLowBits_def word_sle_def
asid_low_bits_def)
done
definition
generic_frame_cap_get_capFMappedASID_CL :: "cap_CL option \<Rightarrow> word32" where
"generic_frame_cap_get_capFMappedASID_CL \<equiv> \<lambda>cap. case cap of
Some (Cap_small_frame_cap c) \<Rightarrow>
(cap_small_frame_cap_CL.capFMappedASIDHigh_CL c << asidLowBits)
+ (cap_small_frame_cap_CL.capFMappedASIDLow_CL c)
| Some (Cap_frame_cap c) \<Rightarrow>
(cap_frame_cap_CL.capFMappedASIDHigh_CL c << asidLowBits)
+ (cap_frame_cap_CL.capFMappedASIDLow_CL c)
| Some _ \<Rightarrow> 0"
lemma generic_frame_cap_get_capFMappedASID_spec:
"\<forall>s. \<Gamma> \<turnstile> \<lbrace>s. cap_get_tag \<acute>cap = scast cap_small_frame_cap \<or>
cap_get_tag \<acute>cap = scast cap_frame_cap\<rbrace>
Call generic_frame_cap_get_capFMappedASID_'proc
\<lbrace>\<acute>ret__unsigned_long = generic_frame_cap_get_capFMappedASID_CL (cap_lift \<^bsup>s\<^esup>cap)\<rbrace>"
apply vcg
apply (clarsimp simp: generic_frame_cap_get_capFMappedASID_CL_def Kernel_C.asidLowBits_def word_sle_def )
apply (intro conjI impI, simp_all)
apply (clarsimp simp: cap_lift_small_frame_cap cap_small_frame_cap_lift_def)
apply (clarsimp simp: cap_lift_frame_cap cap_frame_cap_lift_def)
done
lemma generic_frame_cap_get_capFIsMapped_spec:
"\<forall>s. \<Gamma> \<turnstile> \<lbrace>s. cap_get_tag \<acute>cap = scast cap_small_frame_cap \<or>
cap_get_tag \<acute>cap = scast cap_frame_cap\<rbrace>
Call generic_frame_cap_get_capFIsMapped_'proc
\<lbrace>\<acute>ret__unsigned_long = (if generic_frame_cap_get_capFMappedASID_CL (cap_lift \<^bsup>s\<^esup>cap) \<noteq> 0 then 1 else 0)\<rbrace>"
apply vcg
apply (clarsimp simp: generic_frame_cap_get_capFMappedASID_CL_def if_distrib [where f=scast])
done
definition
generic_frame_cap_get_capFMappedAddress_CL :: "cap_CL option \<Rightarrow> word32" where
"generic_frame_cap_get_capFMappedAddress_CL \<equiv> \<lambda>cap. case cap of
Some (Cap_small_frame_cap c) \<Rightarrow> cap_small_frame_cap_CL.capFMappedAddress_CL c
| Some (Cap_frame_cap c) \<Rightarrow> cap_frame_cap_CL.capFMappedAddress_CL c
| Some _ \<Rightarrow> 0"
lemma generic_frame_cap_get_capFMappedAddress_spec:
"\<forall>s. \<Gamma> \<turnstile> \<lbrace>s. cap_get_tag \<acute>cap = scast cap_small_frame_cap \<or>
cap_get_tag \<acute>cap = scast cap_frame_cap\<rbrace>
Call generic_frame_cap_get_capFMappedAddress_'proc
\<lbrace>\<acute>ret__unsigned_long = generic_frame_cap_get_capFMappedAddress_CL (cap_lift \<^bsup>s\<^esup>cap)\<rbrace>"
apply vcg
apply (clarsimp simp: generic_frame_cap_get_capFMappedAddress_CL_def)
apply (auto simp: cap_lift_small_frame_cap cap_small_frame_cap_lift_def
cap_lift_frame_cap cap_frame_cap_lift_def)
done
definition
generic_frame_cap_set_capFMappedAddress_CL :: "cap_CL option \<Rightarrow> word32 \<Rightarrow> word32 \<Rightarrow> cap_CL option " where
"generic_frame_cap_set_capFMappedAddress_CL \<equiv> \<lambda>cap asid addr. case cap of
Some (Cap_small_frame_cap c) \<Rightarrow>
Some ( Cap_small_frame_cap
(c \<lparr> cap_small_frame_cap_CL.capFMappedASIDHigh_CL := (asid >> asidLowBits) && mask asidHighBits,
cap_small_frame_cap_CL.capFMappedASIDLow_CL := asid && mask asidLowBits,
cap_small_frame_cap_CL.capFMappedAddress_CL := addr AND NOT (mask 12) \<rparr>))
| Some (Cap_frame_cap c) \<Rightarrow>
Some ( Cap_frame_cap
(c \<lparr> cap_frame_cap_CL.capFMappedASIDHigh_CL := (asid >> asidLowBits) && mask asidHighBits,
cap_frame_cap_CL.capFMappedASIDLow_CL := asid && mask asidLowBits,
cap_frame_cap_CL.capFMappedAddress_CL := addr AND NOT (mask 14) \<rparr>))
| Some ccap \<Rightarrow> Some ccap"
lemma generic_frame_cap_set_capFMappedAddress_spec:
"\<forall>s. \<Gamma> \<turnstile> \<lbrace>s. cap_get_tag \<acute>cap = scast cap_small_frame_cap \<or>
cap_get_tag \<acute>cap = scast cap_frame_cap\<rbrace>
Call generic_frame_cap_set_capFMappedAddress_'proc
\<lbrace> cap_lift \<acute>ret__struct_cap_C
= generic_frame_cap_set_capFMappedAddress_CL (cap_lift \<^bsup>s\<^esup>cap) (\<^bsup>s\<^esup>asid ) (\<^bsup>s\<^esup>addr ) \<rbrace>"
apply vcg
apply (clarsimp simp: generic_frame_cap_set_capFMappedAddress_CL_def)
apply (intro conjI impI)
apply (clarsimp simp: cap_lift_small_frame_cap cap_small_frame_cap_lift_def
cap_lift_frame_cap cap_frame_cap_lift_def)+
done
lemma clift_ptr_safe:
"clift (h, x) ptr = Some a
\<Longrightarrow> ptr_safe ptr x"
by (erule lift_t_ptr_safe[where g = c_guard])
lemma clift_ptr_safe2:
"clift htd ptr = Some a
\<Longrightarrow> ptr_safe ptr (hrs_htd htd)"
by (cases htd, simp add: hrs_htd_def clift_ptr_safe)
lemma generic_frame_cap_ptr_set_capFMappedAddress_spec:
"\<forall>s cte_slot.
\<Gamma> \<turnstile> \<lbrace>s. (\<exists> cap. cslift s \<^bsup>s\<^esup>cap_ptr = Some cap \<and> cap_lift cap \<noteq> None \<and>
(cap_get_tag cap = scast cap_small_frame_cap \<or>
cap_get_tag cap = scast cap_frame_cap)) \<and>
\<acute>cap_ptr = cap_Ptr &(cte_slot\<rightarrow>[''cap_C'']) \<and>
cslift s cte_slot \<noteq> None\<rbrace>
Call generic_frame_cap_ptr_set_capFMappedAddress_'proc
{t. (\<exists>cte' cap'.
generic_frame_cap_set_capFMappedAddress_CL (cap_lift (the (cslift s \<^bsup>s\<^esup>cap_ptr))) \<^bsup>s\<^esup>asid \<^bsup>s\<^esup>addr = Some cap' \<and>
cte_lift cte' = option_map (cap_CL_update (K cap')) (cte_lift (the (cslift s cte_slot))) \<and>
cslift t = cslift s(cte_slot \<mapsto> cte')) \<and> cslift_all_but_cte_C t s
\<and> (hrs_htd \<^bsup>t\<^esup>t_hrs) = (hrs_htd \<^bsup>s\<^esup>t_hrs)}"
apply vcg
apply (clarsimp simp: typ_heap_simps)
apply (subgoal_tac "cap_lift ret__struct_cap_C \<noteq> None")
prefer 2
apply (clarsimp simp: generic_frame_cap_set_capFMappedAddress_CL_def split: cap_CL.splits)
apply (clarsimp simp: clift_ptr_safe2 typ_heap_simps)
apply (rule_tac x="cte_C.cap_C_update (\<lambda>_. ret__struct_cap_C) y" in exI)
apply simp
apply (case_tac y)
apply (clarsimp simp: cte_lift_def)
done
lemma lookupPDSlot_spec:
"\<forall>s. \<Gamma> \<turnstile> {s}
Call lookupPDSlot_'proc
\<lbrace> \<acute>ret__ptr_to_struct_pde_C = Ptr (lookupPDSlot (ptr_val (pd_' s)) (vptr_' s)) \<rbrace>"
apply vcg
apply (clarsimp simp: lookupPDSlot_def)
apply (simp add: ArchVSpaceAcc_A.lookup_pd_slot_def)
apply (simp add: Let_def word_sle_def)
apply (case_tac pd)
apply simp
apply (simp add: word32_shift_by_2)
done
lemma lookupPTSlot_nofail_spec:
"\<forall>s. \<Gamma> \<turnstile> {s}
Call lookupPTSlot_nofail_'proc
\<lbrace> \<acute>ret__ptr_to_struct_pte_C = Ptr (lookupPTSlot_nofail (ptr_val (pt_' s)) (vptr_' s)) \<rbrace>"
apply vcg
apply (clarsimp simp: lookupPTSlot_nofail_def)
apply (simp add: ArchVSpaceAcc_A.lookup_pt_slot_no_fail_def)
apply (simp add: Let_def word_sle_def)
apply (case_tac pt)
apply simp
apply (simp add: word32_shift_by_2)
done
lemma ccorres_pre_getObject_pde:
assumes cc: "\<And>rv. ccorres r xf (P rv) (P' rv) hs (f rv) c"
shows "ccorres r xf
(\<lambda>s. (\<forall>pde. ko_at' pde p s \<longrightarrow> P pde s))
{s. \<forall>pde pde'. cslift s (pde_Ptr p) = Some pde' \<and> cpde_relation pde pde'
\<longrightarrow> s \<in> P' pde}
hs (getObject p >>= (\<lambda>rv. f rv)) c"
apply (rule ccorres_guard_imp2)
apply (rule ccorres_symb_exec_l)
apply (rule ccorres_guard_imp2)
apply (rule cc)
apply (rule conjI)
apply (rule_tac Q="ko_at' rv p s" in conjunct1)
apply assumption
apply assumption
apply (wp getPDE_wp empty_fail_getObject | simp)+
apply clarsimp
apply (erule cmap_relationE1 [OF rf_sr_cpde_relation],
erule ko_at_projectKO_opt)
apply simp
done
(* FIXME: move *)
(* FIXME: delete duplicates in Corres_C *)
lemma ccorres_abstract_cleanup:
"ccorres r xf G G' hs a c \<Longrightarrow>
ccorres r xf G ({s. s \<in> S \<longrightarrow> s \<in> G'} \<inter> S) hs a c"
by (fastforce intro: ccorres_guard_imp)
lemma pde_case_isPageTablePDE:
"(case pde of PageTablePDE a b c \<Rightarrow> fn a b c | _ \<Rightarrow> g)
= (if isPageTablePDE pde then fn (pdeTable pde) (pdeParity pde) (pdeDomain pde) else g)"
by (cases pde, simp_all add: isPageTablePDE_def)
lemma ptrFromPAddr_spec:
"\<forall>s. \<Gamma> \<turnstile> {s}
Call ptrFromPAddr_'proc
\<lbrace> \<acute>ret__ptr_to_void = Ptr (ptrFromPAddr (paddr_' s) ) \<rbrace>"
apply vcg
apply (simp add: Platform.ptrFromPAddr_def physMappingOffset_def
kernelBase_addr_def physBase_def)
done
lemma addrFromPPtr_spec:
"\<forall>s. \<Gamma> \<turnstile> {s}
Call addrFromPPtr_'proc
\<lbrace> \<acute>ret__unsigned_long = (addrFromPPtr (ptr_val (pptr_' s)) ) \<rbrace>"
apply vcg
apply (simp add: addrFromPPtr_def
Platform.addrFromPPtr_def physMappingOffset_def
kernelBase_addr_def physBase_def)
done
abbreviation
"lookupPTSlot_xf \<equiv> liftxf errstate lookupPTSlot_ret_C.status_C lookupPTSlot_ret_C.ptSlot_C ret__struct_lookupPTSlot_ret_C_'"
lemma cpde_relation_pde_coarse:
"cpde_relation pdea pde \<Longrightarrow> (pde_get_tag pde = scast pde_pde_coarse) = isPageTablePDE pdea"
apply (simp add: cpde_relation_def Let_def)
apply (simp add: pde_pde_coarse_lift)
apply (case_tac pdea, simp_all add: isPageTablePDE_def) [1]
apply clarsimp
apply (simp add: pde_pde_coarse_lift_def)
done
lemma lookupPTSlot_ccorres:
"ccorres (lookup_failure_rel \<currency> (\<lambda>rv rv'. rv' = pte_Ptr rv)) lookupPTSlot_xf \<top>
(UNIV \<inter> \<lbrace>\<acute>pd = Ptr pd \<rbrace> \<inter> \<lbrace>\<acute>vptr = vptr \<rbrace>)
[]
(lookupPTSlot pd vptr)
(Call lookupPTSlot_'proc)"
apply (cinit lift: pd_' vptr_')
apply (simp add: liftE_bindE pde_case_isPageTablePDE)
apply (rule ccorres_pre_getObject_pde)
apply csymbr
apply csymbr
apply (rule ccorres_abstract_cleanup)
apply (rule_tac P="(ret__unsigned_long = scast pde_pde_coarse) = (isPageTablePDE rv)"
in ccorres_gen_asm2)
apply (rule ccorres_cond2'[where R=\<top>])
apply (clarsimp simp: Collect_const_mem)
apply simp
apply (rule_tac P=\<top> and P' =UNIV in ccorres_from_vcg_throws)
apply (rule allI, rule conseqPre, vcg)
apply (clarsimp simp: throwError_def return_def syscall_error_rel_def)
apply (clarsimp simp: EXCEPTION_NONE_def EXCEPTION_LOOKUP_FAULT_def)
apply (simp add: lookup_fault_missing_capability_lift)
apply (simp add: mask_def)
apply (rule ccorres_rhs_assoc)+
apply csymbr
apply csymbr
apply csymbr
apply csymbr
apply (rule ccorres_abstract_cleanup)
apply (rule_tac P="ret__unsigned_long = pdeTable rv"
in ccorres_gen_asm2)
apply simp
apply (simp add: word_sle_def)
apply (simp add:liftE_bindE checkPTAt_def)
apply (rule ccorres_stateAssert)
apply (rule_tac R=\<top> and Q' = "UNIV
\<inter> {s. pt_' s = Ptr (ptrFromPAddr ret__unsigned_long)}" in ccorres_symb_exec_r)
apply (rule ccorres_tmp_lift2)
apply ceqv
apply (rule ccorres_Guard_Seq)+
apply csymbr
apply csymbr
apply csymbr
apply csymbr
apply (rule ccorres_return_CE, simp+)[1]
apply (clarsimp simp: Collect_const_mem shiftl_t2n)
apply simp
apply vcg
apply (rule conseqPre, vcg)
apply clarsimp
apply (clarsimp simp: Collect_const_mem)
apply (frule h_t_valid_clift, simp)
apply (intro conjI impI)
apply (clarsimp simp: cpde_relation_def pde_pde_coarse_lift_def
pde_lift_pde_coarse Let_def)
apply (clarsimp split: Hardware_H.pde.split_asm)
apply (drule cpde_relation_pde_coarse, simp)
done
lemma cap_case_isPageDirectoryCap:
"(case cap of capability.ArchObjectCap (arch_capability.PageDirectoryCap pd ( Some asid)) \<Rightarrow> fn pd asid
| _ => g)
= (if ( if (isArchObjectCap cap) then if (isPageDirectoryCap (capCap cap)) then capPDMappedASID (capCap cap) \<noteq> None else False else False)
then fn (capPDBasePtr (capCap cap)) (the ( capPDMappedASID (capCap cap))) else g)"
apply (cases cap, simp_all add: isArchObjectCap_def)
apply (case_tac arch_capability, simp_all add: isPageDirectoryCap_def)
apply (case_tac option, simp_all)
done
(* FIXME: MOVE to CSpaceAcc_C *)
lemma ccorres_pre_gets_armKSASIDTable_ksArchState:
assumes cc: "\<And>rv. ccorres r xf (P rv) (P' rv) hs (f rv) c"
shows "ccorres r xf
(\<lambda>s. (\<forall>rv. armKSASIDTable (ksArchState s) = rv \<longrightarrow> P rv s))
{s. \<forall>rv. s \<in> P' rv }
hs (gets (armKSASIDTable \<circ> ksArchState) >>= (\<lambda>rv. f rv)) c"
apply (rule ccorres_guard_imp)
apply (rule ccorres_symb_exec_l)
defer
apply wp[1]
apply (rule gets_sp)
apply (clarsimp simp: empty_fail_def simpler_gets_def)
apply assumption
apply clarsimp
defer
apply (rule ccorres_guard_imp)
apply (rule cc)
apply clarsimp
apply assumption
apply clarsimp
done
abbreviation
"findPDForASID_xf \<equiv> liftxf errstate findPDForASID_ret_C.status_C findPDForASID_ret_C.pd_C ret__struct_findPDForASID_ret_C_'"
lemma ccorres_pre_getObject_asidpool:
assumes cc: "\<And>rv. ccorres r xf (P rv) (P' rv) hs (f rv) c"
shows "ccorres r xf
(\<lambda>s. (\<forall>asidpool. ko_at' asidpool p s \<longrightarrow> P asidpool s))
{s. \<forall> asidpool asidpool'. cslift s (ap_Ptr p) = Some asidpool' \<and> casid_pool_relation asidpool asidpool'
\<longrightarrow> s \<in> P' asidpool}
hs (getObject p >>= (\<lambda>rv :: asidpool. f rv)) c"
apply (rule ccorres_guard_imp2)
apply (rule ccorres_symb_exec_l)
apply (rule ccorres_guard_imp2)
apply (rule cc)
apply (rule conjI)
apply (rule_tac Q="ko_at' rv p s" in conjunct1)
apply assumption
apply assumption
apply (wp getASID_wp empty_fail_getObject | simp)
apply (wp getASID_wp empty_fail_getObject | simp)
apply (wp getASID_wp empty_fail_getObject | simp)
apply (wp getASID_wp empty_fail_getObject | simp)
apply clarsimp
apply (erule cmap_relationE1 [OF rf_sr_cpspace_asidpool_relation],
erule ko_at_projectKO_opt)
apply simp
done
lemma ccorres_from_vcg_throws_nofail:
"\<forall>\<sigma>. \<Gamma>\<turnstile> {s. P \<sigma> \<and> s \<in> P' \<and> (\<sigma>, s) \<in> srel} c {},
{s. \<not>snd (a \<sigma>) \<longrightarrow> (\<exists>(rv, \<sigma>')\<in>fst (a \<sigma>). (\<sigma>', s) \<in> srel \<and> arrel rv (axf s))} \<Longrightarrow>
ccorres_underlying srel \<Gamma> r xf arrel axf P P' (SKIP # hs) a c"
apply (rule ccorresI')
apply (drule_tac x = s in spec)
apply (drule hoare_sound)
apply (simp add: HoarePartialDef.valid_def cvalid_def)
apply (erule exec_handlers.cases)
apply clarsimp
apply (drule spec, drule spec, drule (1) mp)
apply (clarsimp dest!: exec_handlers_SkipD
simp: split_def unif_rrel_simps elim!: bexI [rotated])
apply clarsimp
apply (drule spec, drule spec, drule (1) mp)
apply clarsimp
apply simp
done
lemma findPDForASID_ccorres:
"ccorres (lookup_failure_rel \<currency> (\<lambda>pdeptrc pdeptr. pdeptr = pde_Ptr pdeptrc)) findPDForASID_xf
(valid_arch_state' and no_0_obj' and (\<lambda>_. asid \<le> mask asid_bits))
(UNIV \<inter> \<lbrace>\<acute>asid = asid\<rbrace> )
[]
(findPDForASID asid)
(Call findPDForASID_'proc)"
apply (rule ccorres_gen_asm)
apply (cinit lift: asid_')
apply (rule ccorres_Guard_Seq)
apply (rule ccorres_Guard_Seq)
apply (rule ccorres_assertE)
apply (rule ccorres_assertE)
apply (rule ccorres_liftE_Seq)
apply (rule_tac r'="\<lambda>asidTable rv'. rv' = option_to_ptr (asidTable (ucast (asid_high_bits_of asid)))"
and xf'=poolPtr_' in ccorres_split_nothrow)
apply (rule ccorres_from_vcg[where P=\<top> and P'=UNIV])
apply (rule allI, rule conseqPre, vcg)
apply (clarsimp simp: simpler_gets_def Kernel_C.asidLowBits_def)
apply (simp add: ucast_asid_high_bits_is_shift)
apply (erule rf_sr_armKSASIDTable)
apply (drule leq_asid_bits_shift)
apply (simp add: asid_high_bits_def mask_def)
apply ceqv
apply (simp add: liftME_def)
apply (simp add: bindE_assoc)
apply (rename_tac asidTable poolPtr)
apply (subgoal_tac "(doE x \<leftarrow> case asidTable (ucast (asid_high_bits_of asid)) of
None \<Rightarrow> throw Fault_H.lookup_failure.InvalidRoot
| Some ptr \<Rightarrow> withoutFailure $ getObject ptr;
(case inv asidpool.ASIDPool x (asid && mask asid_low_bits) of
None \<Rightarrow> throw Fault_H.lookup_failure.InvalidRoot
| Some ptr \<Rightarrow> doE haskell_assertE (ptr \<noteq> 0) [];
withoutFailure $ checkPDAt ptr;
returnOk ptr
odE)
odE) =
(if ( asidTable (ucast (asid_high_bits_of asid))=None)
then (doE x\<leftarrow> throw Fault_H.lookup_failure.InvalidRoot;
(case inv asidpool.ASIDPool x (asid && mask asid_low_bits) of
None \<Rightarrow> throw Fault_H.lookup_failure.InvalidRoot