-
Notifications
You must be signed in to change notification settings - Fork 0
/
ADT_H.thy
1944 lines (1790 loc) · 79.3 KB
/
ADT_H.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)
*)
header {* Abstract datatype for the executable specification *}
theory ADT_H
imports
"../invariant-abstract/ADT_AI"
Syscall_R
begin
text {*
The general refinement calculus (see theory Simulation) requires
the definition of a so-called ``abstract datatype'' for each refinement layer.
This theory defines this datatype for the executable specification.
It is based on the abstract specification because we chose
to base the refinement's observable state on the abstract state.
*}
text {*
The construction of the abstract data type
for the executable specification largely follows
the one for the abstract specification.
*}
definition
Init_H :: "word32 \<Rightarrow> word32 list \<Rightarrow> word32 \<Rightarrow> word32 list \<Rightarrow> asid list \<Rightarrow> word32 \<Rightarrow> kernel_state global_state set"
where
"Init_H entry initFrames initOffset kernelFrames bootFrames data_start \<equiv>
({empty_context} \<times> snd `
fst (initKernel (VPtr entry) (map PPtr initFrames) (PPtr initOffset)
(map PPtr kernelFrames) bootFrames
(newKernelState data_start))) \<times>
{UserMode} \<times> {None}"
definition
"user_mem' s \<equiv> \<lambda>p.
if pointerInUserData p s
then Some (underlying_memory (ksMachineState s) p)
else None"
definition
vm_rights_of :: "vmrights \<Rightarrow> rights set"
where
"vm_rights_of x \<equiv> case x of VMKernelOnly \<Rightarrow> vm_kernel_only
| VMReadOnly \<Rightarrow> vm_read_only
| VMReadWrite \<Rightarrow> vm_read_write"
lemma vm_rights_of_vmrights_map_id[simp]:
"rs \<in> valid_vm_rights \<Longrightarrow> vm_rights_of (vmrights_map rs)= rs"
by (auto simp: vm_rights_of_def vmrights_map_def valid_vm_rights_def
vm_read_write_def vm_read_only_def vm_kernel_only_def)
definition
absPageTable :: "(word32 \<rightharpoonup> Structures_H.kernel_object) \<Rightarrow> obj_ref \<Rightarrow>
word8 \<Rightarrow> ARM_Structs_A.pte"
where
"absPageTable h a \<equiv> %offs.
case (h (a + (ucast offs << 2))) of
Some (KOArch (KOPTE (Hardware_H.InvalidPTE))) \<Rightarrow> ARM_Structs_A.InvalidPTE
| Some (KOArch (KOPTE (Hardware_H.LargePagePTE p c g rights))) \<Rightarrow>
if is_aligned offs 4 then
ARM_Structs_A.LargePagePTE p
{x. c & x=PageCacheable | g & x=Global} (vm_rights_of rights)
else ARM_Structs_A.InvalidPTE
| Some (KOArch (KOPTE (Hardware_H.SmallPagePTE p c g rights))) \<Rightarrow>
ARM_Structs_A.SmallPagePTE p {x. c & x=PageCacheable |
g & x=Global} (vm_rights_of rights)"
definition
absPageDirectory :: "(word32 \<rightharpoonup> Structures_H.kernel_object) \<Rightarrow> obj_ref \<Rightarrow>
12 word \<Rightarrow> ARM_Structs_A.pde"
where
"absPageDirectory h a \<equiv> %offs.
case (h (a + (ucast offs << 2))) of
Some (KOArch (KOPDE (Hardware_H.InvalidPDE))) \<Rightarrow> ARM_Structs_A.InvalidPDE
| Some (KOArch (KOPDE (Hardware_H.PageTablePDE p e mw))) \<Rightarrow>
ARM_Structs_A.PageTablePDE p {x. e & x=ParityEnabled} mw
| Some (KOArch (KOPDE (Hardware_H.SectionPDE p e mw c g rights))) \<Rightarrow>
ARM_Structs_A.SectionPDE p {x. e & x=ParityEnabled |
c & x=PageCacheable |
g & x=Global} mw (vm_rights_of rights)
| Some (KOArch (KOPDE (Hardware_H.SuperSectionPDE p e c g rights))) \<Rightarrow>
if is_aligned offs 4 then
ARM_Structs_A.SuperSectionPDE p
{x. e & x=ParityEnabled | c & x=PageCacheable | g & x=Global}
(vm_rights_of rights)
else ARM_Structs_A.InvalidPDE"
(* Can't pull the whole heap off at once, start with arch specific stuff.*)
definition
absHeapArch :: "(word32 \<rightharpoonup> Structures_H.kernel_object) \<Rightarrow> word32
\<Rightarrow> arch_kernel_object \<rightharpoonup> arch_kernel_obj"
where
"absHeapArch h a \<equiv> %ako.
(case ako of
KOASIDPool (ARMStructures_H.ASIDPool ap) \<Rightarrow>
Some (ARM_Structs_A.ASIDPool (\<lambda>w. ap (ucast w)))
| KOPTE _ \<Rightarrow>
if is_aligned a pt_bits then Some (PageTable (absPageTable h a))
else None
| KOPDE _ \<Rightarrow>
if is_aligned a pd_bits then Some (PageDirectory (absPageDirectory h a))
else None)"
lemma
assumes ptes:
"\<forall>x. (\<exists>pte. ksPSpace \<sigma> x = Some (KOArch (KOPTE pte))) \<longrightarrow>
is_aligned x pt_bits \<longrightarrow>
(\<forall>y\<Colon>word8. \<exists>pte'. ksPSpace \<sigma> (x + (ucast y << 2)) =
Some (KOArch (KOPTE pte')))"
and pte_rights:
"\<forall>x. case ksPSpace \<sigma> x of
Some (KOArch (KOPTE (Hardware_H.LargePagePTE _ _ _ r))) \<Rightarrow>
r \<noteq> VMNoAccess"
"\<forall>x. case ksPSpace \<sigma> x of
Some (KOArch (KOPTE (Hardware_H.SmallPagePTE _ _ _ r))) \<Rightarrow>
r \<noteq> VMNoAccess"
assumes pdes:
"\<forall>x. (\<exists>pde. ksPSpace \<sigma> x = Some (KOArch (KOPDE pde))) \<longrightarrow>
is_aligned x pd_bits \<longrightarrow>
(\<forall>y\<Colon>12 word. \<exists>pde'. ksPSpace \<sigma> (x + (ucast y << 2)) =
Some (KOArch (KOPDE pde')))"
and pde_rights:
"\<forall>x. case ksPSpace \<sigma> x of
Some (KOArch (KOPDE (Hardware_H.SectionPDE _ _ _ _ _ r))) \<Rightarrow>
r \<noteq> VMNoAccess"
"\<forall>x. case ksPSpace \<sigma> x of
Some (KOArch (KOPDE (Hardware_H.SuperSectionPDE _ _ _ _ r))) \<Rightarrow>
r \<noteq> VMNoAccess"
assumes fst_pte:
"\<forall>x. (\<exists>pte. ksPSpace \<sigma> x = Some (KOArch (KOPTE pte))) \<longrightarrow>
(\<exists>pte'. ksPSpace \<sigma> (x && ~~ mask pt_bits) =
Some (KOArch (KOPTE pte')))"
assumes fst_pde:
"\<forall>x. (\<exists>pde. ksPSpace \<sigma> x = Some (KOArch (KOPDE pde))) \<longrightarrow>
(\<exists>pde'. ksPSpace \<sigma> (x && ~~ mask pd_bits) =
Some (KOArch (KOPDE pde')))"
assumes pspace_aligned': "pspace_aligned' \<sigma>"
shows
"pspace_relation
(%x. case ksPSpace \<sigma> x of
Some (KOArch ako) \<Rightarrow>
Option.map ArchObj (absHeapArch (ksPSpace \<sigma>) x ako)
| _ \<Rightarrow> None)
(%x. case ksPSpace \<sigma> x of Some (KOArch _) \<Rightarrow> ksPSpace \<sigma> x | _ \<Rightarrow> None)"
apply (clarsimp simp add: pspace_relation_def dom_def)
apply (rule conjI)
apply (clarsimp simp add: pspace_dom_def dom_def UNION_eq)
apply (rule Collect_cong)
apply (rule iffI)
apply (erule exE)
apply (case_tac "ksPSpace \<sigma> x", simp+)
apply (clarsimp split: option.splits Structures_H.kernel_object.splits)
apply (simp add: absHeapArch_def)
apply (case_tac arch_kernel_object)
apply (clarsimp split: asidpool.splits)
apply (clarsimp split: split_if_asm)
using ptes
apply (erule_tac x=x in allE)
apply simp
apply (erule_tac x=y in allE)
apply clarsimp
apply (clarsimp split: split_if_asm)
using pdes
apply (erule_tac x=x in allE)
apply simp
apply (erule_tac x=y in allE)
apply clarsimp
apply (clarsimp split: option.splits Structures_H.kernel_object.splits)
apply (clarsimp simp add: absHeapArch_def)
apply (case_tac arch_kernel_object)
apply (rule_tac x=y in exI)
apply (clarsimp split: asidpool.splits)
using fst_pte
apply (erule_tac x=y in allE)
apply (clarsimp split: split_if_asm)
apply (rule_tac x="(y && ~~ mask pt_bits)" in exI, simp)
apply (simp add: is_aligned_mask mask_AND_NOT_mask)
apply (simp add: range_composition[symmetric])
apply (rule_tac x="ucast (y >> 2)" in range_eqI)
apply (simp add: pt_bits_def pageBits_def)
apply (simp add: word_size ucast_ucast_mask and_mask_shiftl_comm)
using pspace_aligned'
apply (simp add: pspace_aligned'_def dom_def)
apply (erule_tac x=y in allE)
apply (simp add: objBitsKO_def archObjSize_def is_aligned_neg_mask_eq
and_not_mask[symmetric] AND_NOT_mask_plus_AND_mask_eq)
using fst_pde
apply (erule_tac x=y in allE)
apply clarsimp
apply (rule_tac x="(y && ~~ mask pd_bits)" in exI, simp)
apply (simp add: is_aligned_mask mask_AND_NOT_mask)
apply (simp add: range_composition[symmetric])
apply (rule_tac x="ucast (y >> 2)" in range_eqI)
apply (simp add: pd_bits_def pageBits_def)
apply (simp add: word_size ucast_ucast_mask and_mask_shiftl_comm)
using pspace_aligned'
apply (simp add: pspace_aligned'_def dom_def)
apply (erule_tac x=y in allE)
apply (simp add: objBitsKO_def archObjSize_def is_aligned_neg_mask_eq
and_not_mask[symmetric] AND_NOT_mask_plus_AND_mask_eq)
apply (simp split: option.splits Structures_H.kernel_object.splits)
apply (intro allI)
apply (intro impI)
apply (elim exE)
apply (clarsimp split: option.splits Structures_H.kernel_object.splits)
apply (simp add: absHeapArch_def)
apply (case_tac arch_kernel_object)
apply (clarsimp split: asidpool.splits)
apply (simp add:other_obj_relation_def asid_pool_relation_def o_def inv_def)
apply simp
apply (clarsimp simp: pte_relation_def pte_relation_aligned_def
split: split_if_asm)
using ptes
apply (erule_tac x=x in allE)
apply simp
apply (erule_tac x=y in allE)
apply clarsimp
apply (simp add: absPageTable_def split:option.splits Hardware_H.pte.splits)
apply (clarsimp simp add: vmrights_map_def vm_rights_of_def
vm_kernel_only_def vm_read_only_def vm_read_write_def
split: vmrights.splits)
using pte_rights
apply -[1]
apply (erule_tac x="x + (ucast y << 2)" in allE)+
apply fastforce -- "NOTE: takes quite a while."
apply (clarsimp split: split_if_asm)
using pdes
apply (erule_tac x=x in allE)
apply simp
apply (erule_tac x=y in allE)
apply clarsimp
apply (simp add: pde_relation_def pde_relation_aligned_def)
apply (simp add: absPageDirectory_def
split: option.splits Hardware_H.pde.splits)
apply (clarsimp simp add: vmrights_map_def vm_rights_of_def
vm_kernel_only_def vm_read_only_def vm_read_write_def
split: vmrights.splits)
using pde_rights
apply -[1]
apply (erule_tac x="x + (ucast y << 2)" in allE)+
apply fastforce
done
definition
"EndpointMap ep \<equiv> case ep of
Structures_H.IdleEP \<Rightarrow> Structures_A.IdleEP
| Structures_H.SendEP q \<Rightarrow> Structures_A.SendEP q
| Structures_H.RecvEP q \<Rightarrow> Structures_A.RecvEP q"
definition
"AEndpointMap aep \<equiv> case aep of
Structures_H.IdleAEP \<Rightarrow> Structures_A.IdleAEP
| Structures_H.WaitingAEP q \<Rightarrow> Structures_A.WaitingAEP q
| Structures_H.ActiveAEP b m \<Rightarrow> Structures_A.ActiveAEP b m"
fun
CapabilityMap :: "capability \<Rightarrow> cap"
where
"CapabilityMap capability.NullCap = cap.NullCap"
| "CapabilityMap (capability.UntypedCap ref n idx) = cap.UntypedCap ref n idx"
| "CapabilityMap (capability.EndpointCap ref b sr rr gr) =
cap.EndpointCap ref b {x. sr \<and> x = AllowSend \<or> rr \<and> x = AllowRecv \<or>
gr \<and> x = AllowGrant}"
| "CapabilityMap (capability.AsyncEndpointCap ref b sr rr) =
cap.AsyncEndpointCap ref b {x. sr \<and> x = AllowSend \<or> rr \<and> x = AllowRecv}"
| "CapabilityMap (capability.CNodeCap ref n L l) =
cap.CNodeCap ref n (bin_to_bl l (uint L))"
| "CapabilityMap (capability.ThreadCap ref) = cap.ThreadCap ref"
| "CapabilityMap capability.DomainCap = cap.DomainCap"
| "CapabilityMap (capability.ReplyCap ref master) = cap.ReplyCap ref master"
| "CapabilityMap capability.IRQControlCap = cap.IRQControlCap"
| "CapabilityMap (capability.IRQHandlerCap irq) = cap.IRQHandlerCap irq"
| "CapabilityMap (capability.Zombie p b n) =
cap.Zombie p (case b of ZombieTCB \<Rightarrow> None | ZombieCNode n \<Rightarrow> Some n) n"
| "CapabilityMap (capability.ArchObjectCap (arch_capability.ASIDPoolCap x y)) =
cap.ArchObjectCap (arch_cap.ASIDPoolCap x y)"
| "CapabilityMap (capability.ArchObjectCap (arch_capability.ASIDControlCap)) =
cap.ArchObjectCap (arch_cap.ASIDControlCap)"
| "CapabilityMap (capability.ArchObjectCap
(arch_capability.PageCap word rghts sz data)) =
cap.ArchObjectCap (arch_cap.PageCap word (vm_rights_of rghts) sz data)"
| "CapabilityMap (capability.ArchObjectCap
(arch_capability.PageTableCap word data)) =
cap.ArchObjectCap (arch_cap.PageTableCap word data)"
| "CapabilityMap (capability.ArchObjectCap
(arch_capability.PageDirectoryCap word data)) =
cap.ArchObjectCap (arch_cap.PageDirectoryCap word data)"
lemma cap_relation_CapabilityMap:
"\<lbrakk>\<forall>w r s d. c = capability.ArchObjectCap (arch_capability.PageCap w r s d) \<longrightarrow>
r \<noteq> VMNoAccess;
\<forall>ref n L l. c = capability.CNodeCap ref n L l \<longrightarrow>
of_bl (bin_to_bl l (uint L)) = L\<rbrakk>
\<Longrightarrow> cap_relation (CapabilityMap c) c"
apply (case_tac c, simp_all add: AllowSend_def AllowRecv_def del: bin_to_bl_def)
apply (clarsimp simp add: zbits_map_def split: zombie_type.splits)
apply (case_tac arch_capability,
simp_all add: vmrights_map_def vm_rights_of_def vm_kernel_only_def
vm_read_only_def vm_read_write_def
split: vmrights.splits)
done
lemma cap_relation_imp_CapabilityMap:
"\<lbrakk>wellformed_cap c; cap_relation c c'\<rbrakk> \<Longrightarrow> CapabilityMap c' = c"
apply (case_tac c, simp_all add: AllowSend_def AllowRecv_def
wellformed_cap_simps)
apply (rule set_eqI, clarsimp)
apply (case_tac "x", simp_all)
apply (rule set_eqI, clarsimp)
apply (case_tac "x", simp_all)
apply (simp add: uint_of_bl_is_bl_to_bin bl_bin_bl[simplified])
apply (simp add: zbits_map_def split: option.splits)
apply clarsimp
apply (case_tac arch_cap, simp_all add: wellformed_acap_simps)
done
primrec
ThStateMap :: "Structures_H.thread_state \<Rightarrow> Structures_A.thread_state"
where
"ThStateMap Structures_H.thread_state.Running =
Structures_A.thread_state.Running"
| "ThStateMap Structures_H.thread_state.Restart =
Structures_A.thread_state.Restart"
| "ThStateMap Structures_H.thread_state.Inactive =
Structures_A.thread_state.Inactive"
| "ThStateMap Structures_H.thread_state.IdleThreadState =
Structures_A.thread_state.IdleThreadState"
| "ThStateMap Structures_H.thread_state.BlockedOnReply =
Structures_A.thread_state.BlockedOnReply"
| "ThStateMap (Structures_H.thread_state.BlockedOnReceive oref dimin) =
Structures_A.thread_state.BlockedOnReceive oref dimin"
| "ThStateMap (Structures_H.thread_state.BlockedOnSend oref badge grant call) =
Structures_A.thread_state.BlockedOnSend oref
\<lparr> sender_badge = badge,
sender_can_grant = grant,
sender_is_call = call \<rparr>"
| "ThStateMap (Structures_H.thread_state.BlockedOnAsyncEvent oref) =
Structures_A.thread_state.BlockedOnAsyncEvent oref"
lemma thread_state_relation_ThStateMap:
"thread_state_relation (ThStateMap ts) ts"
by (cases ts) simp_all
lemma thread_state_relation_imp_ThStateMap:
"thread_state_relation ts ts' \<Longrightarrow> ThStateMap ts' = ts"
by (cases ts) simp_all
definition
"LookupFailureMap \<equiv> \<lambda>lf. case lf of
Fault_H.lookup_failure.InvalidRoot \<Rightarrow>
ExceptionTypes_A.lookup_failure.InvalidRoot
| Fault_H.lookup_failure.MissingCapability n \<Rightarrow>
ExceptionTypes_A.lookup_failure.MissingCapability n
| Fault_H.lookup_failure.DepthMismatch n m \<Rightarrow>
ExceptionTypes_A.lookup_failure.DepthMismatch n m
| Fault_H.lookup_failure.GuardMismatch n g l \<Rightarrow>
ExceptionTypes_A.lookup_failure.GuardMismatch n (bin_to_bl l (uint g))"
lemma lookup_failure_map_LookupFailureMap:
"(\<forall>n g l. lf = Fault_H.lookup_failure.GuardMismatch n g l \<longrightarrow>
of_bl (bin_to_bl l (uint g)) = g)
\<Longrightarrow> lookup_failure_map (LookupFailureMap lf) = lf"
by (clarsimp simp add: LookupFailureMap_def lookup_failure_map_def
simp del: bin_to_bl_def
split: lookup_failure.splits)
lemma LookupFailureMap_lookup_failure_map:
"(\<forall>n g. lf = ExceptionTypes_A.GuardMismatch n g \<longrightarrow> length g \<le> 32)
\<Longrightarrow> LookupFailureMap (lookup_failure_map lf) = lf"
by (clarsimp simp add: LookupFailureMap_def lookup_failure_map_def
uint_of_bl_is_bl_to_bin bl_bin_bl
simp del: bin_to_bl_def
split: ExceptionTypes_A.lookup_failure.splits)
primrec
FaultMap :: "Fault_H.fault \<Rightarrow> ExceptionTypes_A.fault"
where
"FaultMap (Fault_H.fault.CapFault ref b failure) =
ExceptionTypes_A.fault.CapFault ref b (LookupFailureMap failure)"
| "FaultMap (Fault_H.fault.VMFault ptr bool) =
ExceptionTypes_A.fault.VMFault ptr bool"
| "FaultMap (Fault_H.fault.UnknownSyscallException n) =
ExceptionTypes_A.fault.UnknownSyscallException n"
| "FaultMap (Fault_H.fault.UserException x y) =
ExceptionTypes_A.fault.UserException x y"
lemma FaultMap_fault_map[simp]:
"valid_fault ft \<Longrightarrow> FaultMap (fault_map ft) = ft"
apply (case_tac ft, simp_all)
apply (simp add: valid_fault_def LookupFailureMap_lookup_failure_map)
done
definition
"TcbMap tcb \<equiv>
\<lparr>tcb_ctable = CapabilityMap (cteCap (tcbCTable tcb)),
tcb_vtable = CapabilityMap (cteCap (tcbVTable tcb)),
tcb_reply = CapabilityMap (cteCap (tcbReply tcb)),
tcb_caller = CapabilityMap (cteCap (tcbCaller tcb)),
tcb_ipcframe = CapabilityMap (cteCap (tcbIPCBufferFrame tcb)),
tcb_state = ThStateMap (tcbState tcb),
tcb_fault_handler = to_bl (tcbFaultHandler tcb),
tcb_ipc_buffer = tcbIPCBuffer tcb,
tcb_context = tcbContext tcb,
tcb_fault = Option.map FaultMap (tcbFault tcb)\<rparr>"
definition
"absCNode sz h a \<equiv> CNode sz (%bl.
if length bl = sz
then Some (CapabilityMap (case (h (a + of_bl bl * 16)) of
Some (KOCTE cte) \<Rightarrow> cteCap cte))
else None)"
definition
absHeap :: "(word32 \<rightharpoonup> vmpage_size) \<Rightarrow> (word32 \<rightharpoonup> nat) \<Rightarrow>
(word32 \<rightharpoonup> Structures_H.kernel_object) \<Rightarrow> Structures_A.kheap"
where
"absHeap ups cns h \<equiv> \<lambda>x.
case h x of
Some (KOEndpoint ep) \<Rightarrow> Some (Endpoint (EndpointMap ep))
| Some (KOAEndpoint aep) \<Rightarrow> Some (AsyncEndpoint (AEndpointMap aep))
| Some KOKernelData \<Rightarrow> undefined (* forbidden by pspace_relation *)
| Some KOUserData \<Rightarrow> Option.map (ArchObj \<circ> DataPage) (ups x)
| Some (KOTCB tcb) \<Rightarrow> Some (TCB (TcbMap tcb))
| Some (KOCTE cte) \<Rightarrow> Option.map (%sz. absCNode sz h x) (cns x)
| Some (KOArch ako) \<Rightarrow> Option.map ArchObj (absHeapArch h x ako)
| None \<Rightarrow> None"
lemma unaligned_page_offsets_helper:
"\<lbrakk>is_aligned y (pageBitsForSize vmpage_size); n\<noteq>0;
n < 2 ^ (pageBitsForSize vmpage_size - pageBits)\<rbrakk>
\<Longrightarrow> \<not> is_aligned (y + n * 2 ^ pageBits :: word32) (pageBitsForSize vmpage_size)"
apply (simp (no_asm_simp) add: is_aligned_mask)
apply (simp add: mask_add_aligned)
apply (cut_tac mask_eq_iff_w2p
[of "pageBitsForSize vmpage_size" "n * 2 ^ pageBits"])
defer
apply (case_tac vmpage_size, simp_all add: pageBits_def word_size)
apply (cut_tac word_power_nonzero[of n pageBits],
simp_all add: word_bits_conv pageBits_def)
defer
apply (case_tac vmpage_size, simp_all add: pageBits_def word_size)
apply (frule less_trans[of n _ "0x100000"], simp+)+
apply clarsimp
apply (case_tac vmpage_size, simp_all add: pageBits_def)
apply (frule_tac i=n and k="0x1000" in word_mult_less_mono1, simp+)+
done
(* FIXME: move *)
lemma unaligned_helper:
"\<lbrakk>is_aligned x n; y\<noteq>0; y < 2 ^ n\<rbrakk> \<Longrightarrow> \<not> is_aligned (x + y) n"
apply (simp (no_asm_simp) add: is_aligned_mask)
apply (simp add: mask_add_aligned)
apply (cut_tac mask_eq_iff_w2p[of n y], simp_all add: word_size)
apply (rule ccontr)
apply (simp add: not_less power_overflow word_bits_conv)
done
lemma
(* NOTE: life would be easier if pspace_aligned and pspace_distinct were defined on PSpace instead of the whole kernel state. *)
assumes pspace_aligned:
"\<forall>x\<in>dom ha. is_aligned (x :: word32) (obj_bits (the (ha x)))"
assumes pspace_distinct:
"\<forall>x y ko ko'.
ha x = Some ko \<and> ha y = Some ko' \<and> x \<noteq> y \<longrightarrow>
{x..x + (2 ^ obj_bits ko - 1)} \<inter> {y..y + (2 ^ obj_bits ko' - 1)} = {}"
shows pspace_aligned_distinct_None:
"\<lbrakk>ha x = Some ko; y \<in> {0<..<2^(obj_bits ko)}\<rbrakk> \<Longrightarrow> ha (x+y) = None"
using pspace_aligned[simplified dom_def, simplified]
apply (erule_tac x=x in allE)
apply (rule ccontr)
apply clarsimp
apply (rename_tac ko')
using pspace_distinct pspace_aligned[simplified dom_def, simplified]
apply (erule_tac x=x in allE)
apply (erule_tac x="x+y" in allE)+
apply (clarsimp simp add: word_gt_0)
apply (clarsimp simp add: ucast_of_nat_small is_aligned_mask mask_2pm1[symmetric])
apply (frule (1) is_aligned_AND_less_0)
apply (clarsimp simp add: word_plus_and_or_coroll le_word_or2)
apply (simp add: word_bool_alg.disj_assoc le_word_or2)
apply (simp add: word_plus_and_or_coroll[symmetric])
apply (subgoal_tac "x + y \<le> x + mask (obj_bits ko)", simp)
apply (rule word_add_le_mono2)
apply (simp add: mask_def plus_one_helper)
apply (thin_tac "~ ?P")+
apply (thin_tac "(?x::'a::len word) < ?y")+
apply (thin_tac "?x = Some ?y")+
apply (thin_tac "?x && mask (obj_bits ko') = 0")
apply (thin_tac "x && y = 0")
apply (clarsimp simp add: dvd_def word_bits_len_of word_bits_conv
and_mask_dvd_nat[symmetric])
apply (cut_tac x=x in unat_lt2p)
apply (cut_tac x="mask (obj_bits ko)::word32" in unat_lt2p)
apply (simp add: nat_mult_commute
nat_add_commute[of "unat (mask (obj_bits ko))"])
apply (case_tac "k=0", simp+)
apply (subgoal_tac "obj_bits ko\<le>32")
prefer 2
apply (rule ccontr)
apply (simp add: not_le)
apply (frule_tac a="2::nat" and n=32 in power_strict_increasing, simp+)
apply (case_tac "k=1", simp)
apply (cut_tac m=k and n="2 ^ obj_bits ko" in n_less_n_mult_m,
(simp(no_asm_simp))+)
apply (simp only:nat_mult_commute)
apply (thin_tac "?x = ?y")+
apply (clarsimp simp add: le_less)
apply (erule disjE)
prefer 2
apply (simp add: mask_def)
apply (subgoal_tac "obj_bits ko <= (31\<Colon>nat)", simp_all)
apply (simp add: mask_def unat_minus_one word_bits_conv)
apply (cut_tac w=k and c="2 ^ obj_bits ko" and b="2^(32-obj_bits ko)"
in less_le_mult_nat)
apply (simp_all add: power_add[symmetric])
apply (rule ccontr)
apply (simp add: not_less)
apply (simp add: le_less[of "2 ^ (32 - obj_bits ko)"])
apply (erule disjE)
prefer 2
apply (clarsimp simp add: power_add[symmetric])
apply clarsimp
apply (drule mult_less_mono1[of "2 ^ (32 - obj_bits ko)" _ "2 ^ obj_bits ko"])
apply (simp add: power_add[symmetric])+
done
lemma
assumes pspace_aligned: "pspace_aligned s"
assumes pspace_distinct: "pspace_distinct s"
shows pspace_aligned_distinct_None':
"\<lbrakk>kheap s x = Some ko; y \<in> {0<..<2^(obj_bits ko)}\<rbrakk> \<Longrightarrow> kheap s (x+y) = None"
apply (rule pspace_aligned_distinct_None)
apply (rule pspace_aligned[simplified pspace_aligned_def])
apply (rule pspace_distinct[simplified pspace_distinct_def])
apply assumption+
done
lemma absHeap_correct:
assumes pspace_aligned: "pspace_aligned s"
assumes pspace_distinct: "pspace_distinct s"
assumes valid_objs: "valid_objs s"
assumes executable_arch_objs: "executable_arch_objs s"
assumes pspace_relation: "pspace_relation (kheap s) (ksPSpace s')"
assumes ghost_relation:
"ghost_relation (kheap s) (gsUserPages s') (gsCNodes s')"
shows
"absHeap (gsUserPages s') (gsCNodes s') (ksPSpace s') = kheap s"
proof -
from ghost_relation
have gsUserPages:
"\<And>a sz. kheap s a = Some (ArchObj (DataPage sz)) \<longleftrightarrow>
gsUserPages s' a = Some sz"
and gsCNodes:
"\<And>a n. (\<exists>cs. kheap s a = Some (CNode n cs) \<and> well_formed_cnode_n n cs) \<longleftrightarrow>
gsCNodes s' a = Some n"
by (simp_all add: ghost_relation_def)
show "?thesis"
apply (rule ext)
apply (simp add: absHeap_def split: option.splits)
apply (rule conjI)
using pspace_relation
apply (clarsimp simp add: pspace_relation_def pspace_dom_def UNION_eq
dom_def Collect_eq)
apply (erule_tac x=x in allE)
apply clarsimp
apply (case_tac "kheap s x", simp)
apply (erule_tac x=x in allE, clarsimp)
apply (erule_tac x=x in allE, simp add: Ball_def)
apply (erule_tac x=x in allE, clarsimp)
apply (case_tac a)
apply (simp_all add: other_obj_relation_def
split: split_if_asm Structures_H.kernel_object.splits)
apply (rename_tac sz cs)
apply (clarsimp simp add: image_def cte_map_def
well_formed_cnode_n_def Collect_eq dom_def)
apply (erule_tac x="replicate sz False" in allE)+
apply simp
apply (case_tac arch_kernel_obj, simp_all add: image_def)
apply (erule_tac x=0 in allE, simp)
apply (erule_tac x=0 in allE, simp)
apply clarsimp
apply (erule_tac x=0 in allE, simp add: pageBits_def)
apply (case_tac vmpage_size, simp_all)
apply clarsimp
apply (intro conjI impI allI)
apply (erule pspace_dom_relatedE[OF _ pspace_relation])
apply clarsimp
apply (case_tac ko, simp_all add: other_obj_relation_def)
apply (clarsimp simp add: cte_relation_def split: split_if_asm)
apply (clarsimp simp add: ep_relation_def EndpointMap_def
split: Structures_A.endpoint.splits)
apply (clarsimp simp add: EndpointMap_def
split: Structures_A.endpoint.splits)
apply (case_tac arch_kernel_obj,
simp_all add: other_obj_relation_def)
apply (clarsimp simp add: pte_relation_def)
apply (clarsimp simp add: pde_relation_def)
apply clarsimp+
apply (erule pspace_dom_relatedE[OF _ pspace_relation])
apply (case_tac ko, simp_all add: other_obj_relation_def)
apply (clarsimp simp add: cte_relation_def split: split_if_asm)
apply (clarsimp simp add: aep_relation_def AEndpointMap_def
split: Structures_A.async_ep.splits)
apply (clarsimp simp add: AEndpointMap_def
split: Structures_A.async_ep.splits)
apply (case_tac arch_kernel_obj, simp_all add:other_obj_relation_def)
apply (clarsimp simp add: pte_relation_def)
apply (clarsimp simp add: pde_relation_def)
apply clarsimp+
apply (erule pspace_dom_relatedE[OF _ pspace_relation])
apply (case_tac ko, simp_all add: other_obj_relation_def)
apply (clarsimp simp add: cte_relation_def split: split_if_asm)
apply (case_tac arch_kernel_obj, simp_all add: other_obj_relation_def)
apply (clarsimp simp add: pte_relation_def)
apply (clarsimp simp add: pde_relation_def)
apply clarsimp+
apply (erule pspace_dom_relatedE[OF _ pspace_relation])
apply (case_tac ko, simp_all add: other_obj_relation_def)
apply (clarsimp simp add: cte_relation_def split: split_if_asm)
apply (case_tac arch_kernel_obj, simp_all add: other_obj_relation_def)
apply (clarsimp simp add: pte_relation_def)
apply (clarsimp simp add: pde_relation_def)
apply (cut_tac a=y and sz=vmpage_size in gsUserPages, clarsimp)
apply (case_tac "n=0", simp)
apply (case_tac "kheap s (y + n * 2 ^ pageBits)")
apply (rule ccontr)
apply (clarsimp simp: gsUserPages[symmetric, THEN iffD1])
using pspace_aligned
apply (simp add: pspace_aligned_def dom_def)
apply (erule_tac x=y in allE)
apply (case_tac "n=0",simp+)
apply (frule (2) unaligned_page_offsets_helper)
apply (frule_tac y="n*2^pageBits" in pspace_aligned_distinct_None'
[OF pspace_aligned pspace_distinct])
apply simp
apply (rule conjI, clarsimp simp add: word_gt_0)
apply (simp add: is_aligned_mask)
apply (clarsimp simp add: pageBits_def mask_def)
apply (case_tac vmpage_size, simp_all)
apply (frule_tac i=n and k="0x1000" in word_mult_less_mono1, simp+)+
apply (erule pspace_dom_relatedE[OF _ pspace_relation])
apply (case_tac ko, simp_all add: other_obj_relation_def)
apply (clarsimp simp add: cte_relation_def split: split_if_asm)
prefer 2
apply (case_tac arch_kernel_obj, simp_all add: other_obj_relation_def)
apply (clarsimp simp add: pte_relation_def)
apply (clarsimp simp add: pde_relation_def)
apply clarsimp+
apply (clarsimp simp add: TcbMap_def tcb_relation_def valid_obj_def)
apply (case_tac tcb, clarsimp)
apply (case_tac tcb_exta, clarsimp)
apply (simp add: thread_state_relation_imp_ThStateMap)
apply (subgoal_tac "Option.map FaultMap option = tcb_fault")
prefer 2
apply (simp add: fault_option_relation_def)
using valid_objs[simplified valid_objs_def dom_def fun_app_def,
simplified]
apply (erule_tac x=y in allE)
apply (clarsimp simp: valid_obj_def valid_tcb_def
split: option.splits)
using valid_objs[simplified valid_objs_def Ball_def dom_def fun_app_def]
apply (erule_tac x=y in allE)
apply (clarsimp simp add: cap_relation_imp_CapabilityMap valid_obj_def
valid_tcb_def ran_tcb_cap_cases valid_cap_def2)
apply (simp add: absCNode_def cte_map_def)
apply (erule pspace_dom_relatedE[OF _ pspace_relation])
apply (case_tac ko, simp_all add: other_obj_relation_def
split: split_if_asm)
prefer 2
apply (case_tac arch_kernel_obj, simp_all add: other_obj_relation_def)
apply (clarsimp simp add: pte_relation_def)
apply (clarsimp simp add: pde_relation_def)
apply clarsimp
apply (simp add: cte_map_def)
apply (clarsimp simp add: cte_relation_def)
apply (cut_tac a=y and n=sz in gsCNodes, clarsimp)
using pspace_aligned[simplified pspace_aligned_def]
apply (drule_tac x=y in bspec, clarsimp)
apply (clarsimp simp add: obj_bits.simps(1) cte_level_bits_def)
apply (case_tac "(of_bl ya::word32) * 0x10 = 0", simp)
apply (rule ext)
apply simp
apply (rule conjI)
prefer 2
using valid_objs[simplified valid_objs_def Ball_def dom_def
fun_app_def]
apply (erule_tac x=y in allE)
apply (clarsimp simp add: valid_obj_def valid_cs_def valid_cs_size_def
well_formed_cnode_n_def dom_def Collect_eq)
apply (frule_tac x=ya in spec, simp)
apply (erule_tac x=bl in allE)
apply clarsimp+
apply (frule pspace_relation_absD[OF _ pspace_relation])
apply (simp add: cte_map_def)
apply (drule_tac x="y + of_bl bl * 0x10" in spec)
apply clarsimp
apply (erule_tac x="cte_relation bl" in allE)
apply (erule impE)
apply (fastforce simp add: well_formed_cnode_n_def)
apply clarsimp
apply (clarsimp simp add: cte_relation_def)
apply (rule cap_relation_imp_CapabilityMap)
using valid_objs[simplified valid_objs_def Ball_def dom_def
fun_app_def]
apply (erule_tac x=y in allE)
apply (clarsimp simp:valid_obj_def valid_cs_def valid_cap_def2 ran_def)
apply fastforce+
apply (subgoal_tac "kheap s (y + of_bl ya * 0x10) = None")
prefer 2
using valid_objs[simplified valid_objs_def Ball_def dom_def fun_app_def]
apply (erule_tac x=y in allE)
apply (clarsimp simp add: valid_obj_def valid_cs_def valid_cs_size_def)
apply (rule pspace_aligned_distinct_None'[OF
pspace_aligned pspace_distinct], assumption)
apply (clarsimp simp: obj_bits.simps(1) cte_level_bits_def dom_def
word_neq_0_conv power_add mult_commute[of 16])
apply (simp add: well_formed_cnode_n_def dom_def Collect_eq)
apply (erule_tac x=ya in allE)+
apply (rule word_mult_less_mono1)
apply (subgoal_tac "sz = length ya")
apply simp
apply (rule of_bl_length, (simp add: word_bits_def)+)[1]
apply fastforce
apply simp
apply (simp add: word_bits_conv cte_level_bits_def)
apply (drule_tac a="2::nat" in power_strict_increasing, simp+)
apply (rule ccontr, clarsimp)
apply (cut_tac a="y + of_bl ya * 0x10" and n=yc in gsCNodes)
apply clarsimp
(* mapping architecture-specific objects *)
apply clarsimp
apply (erule pspace_dom_relatedE[OF _ pspace_relation])
apply (case_tac ko, simp_all add: other_obj_relation_def)
apply (clarsimp simp add: cte_relation_def split: split_if_asm)
apply (case_tac arch_kernel_object, simp_all add: absHeapArch_def
split: asidpool.splits)
apply clarsimp
apply (case_tac arch_kernel_obj)
apply (simp add: other_obj_relation_def asid_pool_relation_def
inv_def o_def)
apply (clarsimp simp add: pte_relation_def)
apply (clarsimp simp add: pde_relation_def)
apply clarsimp+
apply (case_tac arch_kernel_obj)
apply (simp add: other_obj_relation_def asid_pool_relation_def inv_def
o_def)
using pspace_aligned[simplified pspace_aligned_def Ball_def dom_def]
apply (erule_tac x=y in allE)
apply (clarsimp simp add: pte_relation_def absPageTable_def
pt_bits_def pageBits_def)
apply (rule conjI)
prefer 2
apply clarsimp
apply (rule sym)
apply (rule pspace_aligned_distinct_None'
[OF pspace_aligned pspace_distinct], simp+)
apply (cut_tac x=ya and n="2^10" in
ucast_less_shiftl_helper[simplified word_bits_conv], simp+)
apply (clarsimp simp add: word_gt_0)
apply clarsimp
apply (subgoal_tac "ucast ya << 2 = 0")
prefer 2
apply (rule ccontr)
apply (frule_tac x=y in unaligned_helper, assumption)
apply (rule ucast_less_shiftl_helper, simp_all)
apply (simp add: word_bits_conv)
apply (rule ext)
apply (frule pspace_relation_absD[OF _ pspace_relation])
apply simp
apply (erule_tac x=offs in allE)
apply (clarsimp simp add: pte_relation_def)
using valid_objs[simplified valid_objs_def fun_app_def dom_def,
simplified]
apply (erule_tac x=y in allE)
apply (clarsimp simp add: valid_obj_def wellformed_pte_def)
apply (erule_tac x=offs in allE)
apply (case_tac pte, simp_all add: pte_relation_aligned_def)[1]
apply (clarsimp split: ARM_Structs_A.pte.splits)
apply (rule set_eqI, clarsimp)
apply (case_tac x, simp_all)
using executable_arch_objs[simplified executable_arch_objs_def]
apply (erule_tac x=y in allE)
apply (clarsimp simp: obj_at_def executable_pte_def)
apply (erule_tac x=offs in allE)
apply clarsimp
apply (clarsimp split: ARM_Structs_A.pte.splits)
apply (rule set_eqI, clarsimp)
apply (case_tac x, simp_all)
using executable_arch_objs[simplified executable_arch_objs_def]
apply (erule_tac x=y in allE)
apply (clarsimp simp: obj_at_def executable_pte_def)
apply (erule_tac x=offs in allE)
apply clarsimp
apply (clarsimp simp add: pde_relation_def)
apply clarsimp+
apply (case_tac arch_kernel_obj)
apply (simp add: other_obj_relation_def asid_pool_relation_def inv_def
o_def)
apply (clarsimp simp add: pte_relation_def)
using pspace_aligned
apply (simp add: pspace_aligned_def dom_def)
apply (erule_tac x=y in allE)
apply (clarsimp simp add: pde_relation_def absPageDirectory_def
pd_bits_def pageBits_def)
apply (rule conjI)
prefer 2
apply clarsimp
apply (rule sym)
apply (rule pspace_aligned_distinct_None'
[OF pspace_aligned pspace_distinct], simp+)
apply (cut_tac x=ya and n="2^14" in
ucast_less_shiftl_helper[simplified word_bits_conv], simp+)
apply (clarsimp simp add: word_gt_0)
apply clarsimp
apply (subgoal_tac "ucast ya << 2 = 0")
prefer 2
apply (rule ccontr)
apply (frule_tac x=y in unaligned_helper, assumption)
apply (rule ucast_less_shiftl_helper, simp_all)
apply (simp add: word_bits_conv)
apply (rule ext)
apply (frule pspace_relation_absD[OF _ pspace_relation])
apply simp
apply (erule_tac x=offs in allE)
apply (clarsimp simp add: pde_relation_def)
using valid_objs[simplified valid_objs_def fun_app_def dom_def,simplified]
apply (erule_tac x=y in allE)
apply (clarsimp simp add: valid_obj_def wellformed_pde_def)
apply (erule_tac x=offs in allE)
apply (case_tac pde, simp_all add: pde_relation_aligned_def)[1]
apply (clarsimp split: ARM_Structs_A.pde.splits)+
apply (fastforce simp add: subset_eq)
apply (clarsimp split: ARM_Structs_A.pde.splits)
apply (rule set_eqI, clarsimp)
apply (case_tac x, simp_all)
using executable_arch_objs[simplified executable_arch_objs_def]
apply (erule_tac x=y in allE)
apply (clarsimp simp: obj_at_def executable_pde_def)
apply (erule_tac x=offs in allE)
apply clarsimp
apply (clarsimp split: ARM_Structs_A.pde.splits)
apply (rule set_eqI, clarsimp)
apply (case_tac x, simp_all)
using executable_arch_objs[simplified executable_arch_objs_def]
apply (erule_tac x=y in allE)
apply (clarsimp simp: obj_at_def executable_pde_def)
apply (erule_tac x=offs in allE)
apply clarsimp
apply (clarsimp simp add: pde_relation_def)
done
qed
definition
"EtcbMap tcb \<equiv>
\<lparr>tcb_priority = tcbPriority tcb,
time_slice = tcbTimeSlice tcb,
tcb_domain = tcbDomain tcb\<rparr>"
definition
absEkheap :: "(word32 \<rightharpoonup> Structures_H.kernel_object) \<Rightarrow> obj_ref \<Rightarrow> etcb option"
where
"absEkheap h \<equiv> \<lambda>x.
case h x of
Some (KOTCB tcb) \<Rightarrow> Some (EtcbMap tcb)
| _ \<Rightarrow> None"
lemma absEkheap_correct:
assumes pspace_relation: "pspace_relation (kheap s) (ksPSpace s')"
assumes ekheap_relation: "ekheap_relation (ekheap s) (ksPSpace s')"
assumes vetcbs: "valid_etcbs s"
shows
"absEkheap (ksPSpace s') = ekheap s"
apply (rule ext)
apply (clarsimp simp: absEkheap_def split: option.splits Structures_H.kernel_object.splits)
apply (subgoal_tac "\<forall>x. (\<exists>tcb. kheap s x = Some (TCB tcb)) =
(\<exists>tcb'. ksPSpace s' x = Some (KOTCB tcb'))")
using vetcbs ekheap_relation
apply (clarsimp simp: valid_etcbs_def is_etcb_at_def dom_def ekheap_relation_def valid_etcbs_def st_tcb_at_def obj_at_def)
apply (erule_tac x=x in allE)+
apply (rule conjI, force)
apply clarsimp
apply (rule conjI, clarsimp simp: EtcbMap_def etcb_relation_def)+
apply clarsimp
using pspace_relation
apply (clarsimp simp add: pspace_relation_def pspace_dom_def UNION_eq
dom_def Collect_eq)
apply (rule iffI)
apply (erule_tac x=x in allE)+
apply (case_tac "ksPSpace s' x", clarsimp)
apply (erule_tac x=x in allE, clarsimp)
apply clarsimp
apply (case_tac a, simp_all add: other_obj_relation_def)
apply (insert pspace_relation)
apply (clarsimp simp: obj_at'_def projectKOs)
apply (erule(1) pspace_dom_relatedE)
apply (erule(1) obj_relation_cutsE, simp_all)
apply (clarsimp simp: other_obj_relation_def
split: Structures_A.kernel_object.split_asm
ARM_Structs_A.arch_kernel_obj.split_asm)
done
text {* The following function can be used to reverse cte_map. *}
definition
"cteMap cns \<equiv> \<lambda>p.
let P = (%(a,bl). cte_map (a,bl) = p \<and> cns a = Some (length bl))
in if \<exists>x. P x then (SOME x. P x)
else (p && ~~ mask 9, bin_to_bl 3 (uint (p>>4)))"
term cteMap
lemma wf_unique':
"P (THE x. \<forall>y\<in>dom fun. length y = x) \<Longrightarrow>
well_formed_cnode_n n fun \<Longrightarrow> P n"
apply (subgoal_tac "(THE x. \<forall>y\<in>dom fun. length y = x) = n")
apply simp
apply (rule the_equality)
apply (clarsimp simp add: well_formed_cnode_n_def dom_def Collect_eq)+
apply (erule impE)
apply (rule_tac x="replicate n False" in exI, simp)
apply simp
done
lemma tcb_cap_cases_length:
"tcb_cap_cases b = Some x \<Longrightarrow> length b = 3"
by (simp add: tcb_cap_cases_def tcb_cnode_index_def split: split_if_asm)
lemma of_bl_mult_and_not_mask_eq:
"\<lbrakk>is_aligned (a :: word32) n; length b + m \<le> n\<rbrakk>
\<Longrightarrow> a + of_bl b * (2^m) && ~~ mask n = a"
apply (simp add: shiftl_t2n[simplified mult_commute, symmetric])
apply (simp add: mask_out_add_aligned[where q="of_bl b << m", symmetric])
apply (case_tac "n<32")
prefer 2
apply (simp add: not_less power_overflow mask_def)
apply (simp add: mask_eq_x_eq_0[symmetric])
apply (rule less_mask_eq)
apply (rule shiftl_less_t2n, simp_all)
apply (cut_tac 'a=32 and xs=b in of_bl_length, simp)
apply (drule nat_move_sub_le)
apply (drule two_power_increasing[where 'a=32], simp)
apply (drule (2) less_le_trans)
done
lemma bin_to_bl_of_bl_eq:
"\<lbrakk>is_aligned (a :: word32) n; length b + 4 \<le> n; length b + 4 < 32\<rbrakk>
\<Longrightarrow> bin_to_bl (length b) (uint ((a + of_bl b * 0x10) >> 4)) = b"
apply (subst word_plus_and_or_coroll)
apply (erule is_aligned_get_word_bits)
apply (rule is_aligned_AND_less_0)
apply (simp add: is_aligned_mask)
apply (rule order_less_le_trans)
apply (rule of_bl_length2)
apply (simp add: word_bits_conv cte_level_bits_def)
apply (simp add: two_power_increasing)
apply simp
apply (rule nth_equalityI)
apply (simp only: len_bin_to_bl)
apply (clarsimp simp only: len_bin_to_bl nth_bin_to_bl
word_test_bit_def[symmetric])
apply (simp add: nth_shiftr nth_shiftl
shiftl_t2n[where n=4, simplified mult_commute,
simplified, symmetric])
apply (simp add: is_aligned_nth[THEN iffD1, rule_format]
test_bit_of_bl nth_rev)
apply (case_tac "b ! i", simp_all)
apply arith
done
lemma CNode_implies_KOCTE:
"\<lbrakk>pspace_relation (kheap s) (ksPSpace s');
kheap s a = Some (CNode sz cs); well_formed_cnode_n sz cs; cs b = Some cap\<rbrakk>
\<Longrightarrow> \<exists>cte. ksPSpace s' (cte_map (a, b)) = Some (KOCTE cte) \<and>
cap_relation cap (cteCap cte)"
apply (clarsimp simp add: pspace_relation_def pspace_dom_def
dom_def UNION_eq Collect_eq)
apply (erule_tac x="cte_map (a, b)" in allE)
apply (erule_tac x=a in allE)
apply clarsimp