theory Dpolicy

lemma opt_cap_Some_asid_real:
  "\<lbrakk> opt_cap ref (transform s) = Some cap; asid \<in> cdl_cap_asid' cap; einvs s \<rbrakk> \<Longrightarrow> is_real_cap cap" apply (case_tac ref) apply (clarsimp simp:opt_cap_def transform_def transform_objects_def slots_of_def) apply (rule_tac P="a=idle_thread s" in case_split) apply (clarsimp simp: map_add_def object_slots_def) apply (case_tac "kheap s a") apply (clarsimp simp: map_add_def object_slots_def) apply (case_tac aa, simp_all add:object_slots_def valid_objs_def nat_split_conv_to_if
                             split: if_split_asm) apply (clarsimp simp:transform_cnode_contents_def is_real_cap_transform) apply (clarsimp simp:transform_cnode_contents_def is_real_cap_transform) apply (frule valid_etcbs_tcb_etcb[rotated], fastforce) apply (clarsimp simp: transform_tcb_def tcb_slot_defs is_real_cap_infer_tcb_bound_notification
                         is_real_cap_transform is_real_cap_infer_tcb_pending_op
                  split: if_split_asm) apply (rename_tac arch_kernel_obj) apply (case_tac arch_kernel_obj; simp) apply (clarsimp simp:transform_asid_pool_contents_def unat_map_def split:if_split_asm) apply (clarsimp simp:transform_asid_pool_entry_def split:option.splits) apply (clarsimp simp:transform_page_table_contents_def unat_map_def split:if_split_asm) apply (clarsimp simp:transform_pte_def split:ARM_A.pte.splits) apply (clarsimp simp:transform_page_directory_contents_def unat_map_def split:if_split_asm) apply (clarsimp simp:transform_pde_def split:ARM_A.pde.splits) done

(* Proof state trace *)
proof (prove)
goal (1 subgoal):
 1. \<lbrakk>opt_cap ref (transform s) = Some cap; asid \<in> cdl_cap_asid' cap; einvs s\<rbrakk> \<Longrightarrow> is_real_cap cap proof (prove)
goal (1 subgoal):
 1. \<And>a b. \<lbrakk>opt_cap ref (transform s) = Some cap; asid \<in> cdl_cap_asid' cap; einvs s; ref = (a, b)\<rbrakk> \<Longrightarrow> is_real_cap cap proof (prove)
goal (1 subgoal):
 1. \<And>a b. \<lbrakk>(case ((\<lambda>ptr. Some cdl_object.Untyped) |` (- {idle_thread s}) ++ (\<lambda>ptr. map_option (transform_object (machine_state s) ptr ((ekheap s |` (- {idle_thread s})) ptr)) ((kheap s |` (- {idle_thread s})) ptr))) a of None \<Rightarrow> \<lambda>x. None | Some x2 \<Rightarrow> object_slots x2) b = Some cap; asid \<in> cdl_cap_asid' cap; ref = (a, b); invs s; valid_list s; valid_sched s\<rbrakk> \<Longrightarrow> is_real_cap cap proof (prove)
goal (2 subgoals):
 1. \<And>a b. \<lbrakk>(case ((\<lambda>ptr. Some cdl_object.Untyped) |` (- {idle_thread s}) ++ (\<lambda>ptr. map_option (transform_object (machine_state s) ptr ((ekheap s |` (- {idle_thread s})) ptr)) ((kheap s |` (- {idle_thread s})) ptr))) a of None \<Rightarrow> \<lambda>x. None | Some x2 \<Rightarrow> object_slots x2) b = Some cap; asid \<in> cdl_cap_asid' cap; ref = (a, b); invs s; valid_list s; valid_sched s; a = idle_thread s\<rbrakk> \<Longrightarrow> is_real_cap cap
 2. \<And>a b. \<lbrakk>(case ((\<lambda>ptr. Some cdl_object.Untyped) |` (- {idle_thread s}) ++ (\<lambda>ptr. map_option (transform_object (machine_state s) ptr ((ekheap s |` (- {idle_thread s})) ptr)) ((kheap s |` (- {idle_thread s})) ptr))) a of None \<Rightarrow> \<lambda>x. None | Some x2 \<Rightarrow> object_slots x2) b = Some cap; asid \<in> cdl_cap_asid' cap; ref = (a, b); invs s; valid_list s; valid_sched s; a \<noteq> idle_thread s\<rbrakk> \<Longrightarrow> is_real_cap cap proof (prove)
goal (1 subgoal):
 1. \<And>a b. \<lbrakk>(case ((\<lambda>ptr. Some cdl_object.Untyped) |` (- {idle_thread s}) ++ (\<lambda>ptr. map_option (transform_object (machine_state s) ptr ((ekheap s |` (- {idle_thread s})) ptr)) ((kheap s |` (- {idle_thread s})) ptr))) a of None \<Rightarrow> \<lambda>x. None | Some x2 \<Rightarrow> object_slots x2) b = Some cap; asid \<in> cdl_cap_asid' cap; ref = (a, b); invs s; valid_list s; valid_sched s; a \<noteq> idle_thread s\<rbrakk> \<Longrightarrow> is_real_cap cap proof (prove)
goal (2 subgoals):
 1. \<And>a b. \<lbrakk>(case ((\<lambda>ptr. Some cdl_object.Untyped) |` (- {idle_thread s}) ++ (\<lambda>ptr. map_option (transform_object (machine_state s) ptr ((ekheap s |` (- {idle_thread s})) ptr)) ((kheap s |` (- {idle_thread s})) ptr))) a of None \<Rightarrow> \<lambda>x. None | Some x2 \<Rightarrow> object_slots x2) b = Some cap; asid \<in> cdl_cap_asid' cap; ref = (a, b); invs s; valid_list s; valid_sched s; a \<noteq> idle_thread s; kheap s a = None\<rbrakk> \<Longrightarrow> is_real_cap cap
 2. \<And>a b aa. \<lbrakk>(case ((\<lambda>ptr. Some cdl_object.Untyped) |` (- {idle_thread s}) ++ (\<lambda>ptr. map_option (transform_object (machine_state s) ptr ((ekheap s |` (- {idle_thread s})) ptr)) ((kheap s |` (- {idle_thread s})) ptr))) a of None \<Rightarrow> \<lambda>x. None | Some x2 \<Rightarrow> object_slots x2) b = Some cap; asid \<in> cdl_cap_asid' cap; ref = (a, b); invs s; valid_list s; valid_sched s; a \<noteq> idle_thread s; kheap s a = Some aa\<rbrakk> \<Longrightarrow> is_real_cap cap proof (prove)
goal (1 subgoal):
 1. \<And>a b aa. \<lbrakk>(case ((\<lambda>ptr. Some cdl_object.Untyped) |` (- {idle_thread s}) ++ (\<lambda>ptr. map_option (transform_object (machine_state s) ptr ((ekheap s |` (- {idle_thread s})) ptr)) ((kheap s |` (- {idle_thread s})) ptr))) a of None \<Rightarrow> \<lambda>x. None | Some x2 \<Rightarrow> object_slots x2) b = Some cap; asid \<in> cdl_cap_asid' cap; ref = (a, b); invs s; valid_list s; valid_sched s; a \<noteq> idle_thread s; kheap s a = Some aa\<rbrakk> \<Longrightarrow> is_real_cap cap proof (prove)
goal (4 subgoals):
 1. \<And>a b aa x11 x12. \<lbrakk>asid \<in> cdl_cap_asid' cap; ref = (a, b); invs s; valid_list s; valid_sched s; a \<noteq> idle_thread s; kheap s a = Some (kernel_object.CNode 0 x12); aa = kernel_object.CNode 0 x12; x11 = 0; transform_cnode_contents 0 x12 b = Some cap\<rbrakk> \<Longrightarrow> is_real_cap cap
 2. \<And>a b aa x11 x12. \<lbrakk>asid \<in> cdl_cap_asid' cap; ref = (a, b); invs s; valid_list s; valid_sched s; a \<noteq> idle_thread s; kheap s a = Some (kernel_object.CNode x11 x12); aa = kernel_object.CNode x11 x12; 0 < x11; transform_cnode_contents x11 x12 b = Some cap\<rbrakk> \<Longrightarrow> is_real_cap cap
 3. \<And>a b aa x2. \<lbrakk>(case case ekheap s a of Some x2a \<Rightarrow> transform_tcb (machine_state s) a x2 x2a of Tcb x \<Rightarrow> cdl_tcb_caps x | cdl_object.CNode x \<Rightarrow> cdl_cnode_caps x | AsidPool x \<Rightarrow> cdl_asid_pool_caps x | cdl_object.PageTable x \<Rightarrow> cdl_page_table_caps x | cdl_object.PageDirectory x \<Rightarrow> cdl_page_directory_caps x | IRQNode x \<Rightarrow> cdl_irq_node_caps x | _ \<Rightarrow> \<lambda>x. None) b = Some cap; asid \<in> cdl_cap_asid' cap; ref = (a, b); invs s; valid_list s; valid_sched s; a \<noteq> idle_thread s; kheap s a = Some (TCB x2); aa = TCB x2\<rbrakk> \<Longrightarrow> is_real_cap cap
 4. \<And>a b aa x5. \<lbrakk>(case transform_object (machine_state s) a (ekheap s a) (ArchObj x5) of Tcb x \<Rightarrow> cdl_tcb_caps x | cdl_object.CNode x \<Rightarrow> cdl_cnode_caps x | AsidPool x \<Rightarrow> cdl_asid_pool_caps x | cdl_object.PageTable x \<Rightarrow> cdl_page_table_caps x | cdl_object.PageDirectory x \<Rightarrow> cdl_page_directory_caps x | IRQNode x \<Rightarrow> cdl_irq_node_caps x | _ \<Rightarrow> \<lambda>x. None) b = Some cap; asid \<in> cdl_cap_asid' cap; ref = (a, b); invs s; valid_list s; valid_sched s; a \<noteq> idle_thread s; kheap s a = Some (ArchObj x5); aa = ArchObj x5\<rbrakk> \<Longrightarrow> is_real_cap cap proof (prove)
goal (3 subgoals):
 1. \<And>a b aa x11 x12. \<lbrakk>asid \<in> cdl_cap_asid' cap; ref = (a, b); invs s; valid_list s; valid_sched s; a \<noteq> idle_thread s; kheap s a = Some (kernel_object.CNode x11 x12); aa = kernel_object.CNode x11 x12; 0 < x11; transform_cnode_contents x11 x12 b = Some cap\<rbrakk> \<Longrightarrow> is_real_cap cap
 2. \<And>a b aa x2. \<lbrakk>(case case ekheap s a of Some x2a \<Rightarrow> transform_tcb (machine_state s) a x2 x2a of Tcb x \<Rightarrow> cdl_tcb_caps x | cdl_object.CNode x \<Rightarrow> cdl_cnode_caps x | AsidPool x \<Rightarrow> cdl_asid_pool_caps x | cdl_object.PageTable x \<Rightarrow> cdl_page_table_caps x | cdl_object.PageDirectory x \<Rightarrow> cdl_page_directory_caps x | IRQNode x \<Rightarrow> cdl_irq_node_caps x | _ \<Rightarrow> \<lambda>x. None) b = Some cap; asid \<in> cdl_cap_asid' cap; ref = (a, b); invs s; valid_list s; valid_sched s; a \<noteq> idle_thread s; kheap s a = Some (TCB x2); aa = TCB x2\<rbrakk> \<Longrightarrow> is_real_cap cap
 3. \<And>a b aa x5. \<lbrakk>(case transform_object (machine_state s) a (ekheap s a) (ArchObj x5) of Tcb x \<Rightarrow> cdl_tcb_caps x | cdl_object.CNode x \<Rightarrow> cdl_cnode_caps x | AsidPool x \<Rightarrow> cdl_asid_pool_caps x | cdl_object.PageTable x \<Rightarrow> cdl_page_table_caps x | cdl_object.PageDirectory x \<Rightarrow> cdl_page_directory_caps x | IRQNode x \<Rightarrow> cdl_irq_node_caps x | _ \<Rightarrow> \<lambda>x. None) b = Some cap; asid \<in> cdl_cap_asid' cap; ref = (a, b); invs s; valid_list s; valid_sched s; a \<noteq> idle_thread s; kheap s a = Some (ArchObj x5); aa = ArchObj x5\<rbrakk> \<Longrightarrow> is_real_cap cap proof (prove)
goal (2 subgoals):
 1. \<And>a b aa x2. \<lbrakk>(case case ekheap s a of Some x2a \<Rightarrow> transform_tcb (machine_state s) a x2 x2a of Tcb x \<Rightarrow> cdl_tcb_caps x | cdl_object.CNode x \<Rightarrow> cdl_cnode_caps x | AsidPool x \<Rightarrow> cdl_asid_pool_caps x | cdl_object.PageTable x \<Rightarrow> cdl_page_table_caps x | cdl_object.PageDirectory x \<Rightarrow> cdl_page_directory_caps x | IRQNode x \<Rightarrow> cdl_irq_node_caps x | _ \<Rightarrow> \<lambda>x. None) b = Some cap; asid \<in> cdl_cap_asid' cap; ref = (a, b); invs s; valid_list s; valid_sched s; a \<noteq> idle_thread s; kheap s a = Some (TCB x2); aa = TCB x2\<rbrakk> \<Longrightarrow> is_real_cap cap
 2. \<And>a b aa x5. \<lbrakk>(case transform_object (machine_state s) a (ekheap s a) (ArchObj x5) of Tcb x \<Rightarrow> cdl_tcb_caps x | cdl_object.CNode x \<Rightarrow> cdl_cnode_caps x | AsidPool x \<Rightarrow> cdl_asid_pool_caps x | cdl_object.PageTable x \<Rightarrow> cdl_page_table_caps x | cdl_object.PageDirectory x \<Rightarrow> cdl_page_directory_caps x | IRQNode x \<Rightarrow> cdl_irq_node_caps x | _ \<Rightarrow> \<lambda>x. None) b = Some cap; asid \<in> cdl_cap_asid' cap; ref = (a, b); invs s; valid_list s; valid_sched s; a \<noteq> idle_thread s; kheap s a = Some (ArchObj x5); aa = ArchObj x5\<rbrakk> \<Longrightarrow> is_real_cap cap proof (prove)
goal (2 subgoals):
 1. \<And>a b aa x2. \<lbrakk>(case case ekheap s a of Some x2a \<Rightarrow> transform_tcb (machine_state s) a x2 x2a of Tcb x \<Rightarrow> cdl_tcb_caps x | cdl_object.CNode x \<Rightarrow> cdl_cnode_caps x | AsidPool x \<Rightarrow> cdl_asid_pool_caps x | cdl_object.PageTable x \<Rightarrow> cdl_page_table_caps x | cdl_object.PageDirectory x \<Rightarrow> cdl_page_directory_caps x | IRQNode x \<Rightarrow> cdl_irq_node_caps x | _ \<Rightarrow> \<lambda>x. None) b = Some cap; asid \<in> cdl_cap_asid' cap; ref = (a, b); invs s; valid_list s; valid_sched s; a \<noteq> idle_thread s; kheap s a = Some (TCB x2); aa = TCB x2; \<exists>etcb. ekheap s a = Some etcb\<rbrakk> \<Longrightarrow> is_real_cap cap
 2. \<And>a b aa x5. \<lbrakk>(case transform_object (machine_state s) a (ekheap s a) (ArchObj x5) of Tcb x \<Rightarrow> cdl_tcb_caps x | cdl_object.CNode x \<Rightarrow> cdl_cnode_caps x | AsidPool x \<Rightarrow> cdl_asid_pool_caps x | cdl_object.PageTable x \<Rightarrow> cdl_page_table_caps x | cdl_object.PageDirectory x \<Rightarrow> cdl_page_directory_caps x | IRQNode x \<Rightarrow> cdl_irq_node_caps x | _ \<Rightarrow> \<lambda>x. None) b = Some cap; asid \<in> cdl_cap_asid' cap; ref = (a, b); invs s; valid_list s; valid_sched s; a \<noteq> idle_thread s; kheap s a = Some (ArchObj x5); aa = ArchObj x5\<rbrakk> \<Longrightarrow> is_real_cap cap proof (prove)
goal (1 subgoal):
 1. \<And>a b aa x5. \<lbrakk>(case transform_object (machine_state s) a (ekheap s a) (ArchObj x5) of Tcb x \<Rightarrow> cdl_tcb_caps x | cdl_object.CNode x \<Rightarrow> cdl_cnode_caps x | AsidPool x \<Rightarrow> cdl_asid_pool_caps x | cdl_object.PageTable x \<Rightarrow> cdl_page_table_caps x | cdl_object.PageDirectory x \<Rightarrow> cdl_page_directory_caps x | IRQNode x \<Rightarrow> cdl_irq_node_caps x | _ \<Rightarrow> \<lambda>x. None) b = Some cap; asid \<in> cdl_cap_asid' cap; ref = (a, b); invs s; valid_list s; valid_sched s; a \<noteq> idle_thread s; kheap s a = Some (ArchObj x5); aa = ArchObj x5\<rbrakk> \<Longrightarrow> is_real_cap cap proof (prove)
goal (1 subgoal):
 1. \<And>a b aa arch_kernel_obj. \<lbrakk>(case transform_object (machine_state s) a (ekheap s a) (ArchObj arch_kernel_obj) of Tcb x \<Rightarrow> cdl_tcb_caps x | cdl_object.CNode x \<Rightarrow> cdl_cnode_caps x | AsidPool x \<Rightarrow> cdl_asid_pool_caps x | cdl_object.PageTable x \<Rightarrow> cdl_page_table_caps x | cdl_object.PageDirectory x \<Rightarrow> cdl_page_directory_caps x | IRQNode x \<Rightarrow> cdl_irq_node_caps x | _ \<Rightarrow> \<lambda>x. None) b = Some cap; asid \<in> cdl_cap_asid' cap; ref = (a, b); invs s; valid_list s; valid_sched s; a \<noteq> idle_thread s; kheap s a = Some (ArchObj arch_kernel_obj); aa = ArchObj arch_kernel_obj\<rbrakk> \<Longrightarrow> is_real_cap cap proof (prove)
goal (3 subgoals):
 1. \<And>a b aa arch_kernel_obj x1. \<lbrakk>transform_asid_pool_contents x1 b = Some cap; asid \<in> cdl_cap_asid' cap; ref = (a, b); invs s; valid_list s; valid_sched s; a \<noteq> idle_thread s; kheap s a = Some (ArchObj (ASIDPool x1)); aa = ArchObj (ASIDPool x1); arch_kernel_obj = ASIDPool x1\<rbrakk> \<Longrightarrow> is_real_cap cap
 2. \<And>a b aa arch_kernel_obj x2. \<lbrakk>transform_page_table_contents x2 b = Some cap; asid \<in> cdl_cap_asid' cap; ref = (a, b); invs s; valid_list s; valid_sched s; a \<noteq> idle_thread s; kheap s a = Some (ArchObj (arch_kernel_obj.PageTable x2)); aa = ArchObj (arch_kernel_obj.PageTable x2); arch_kernel_obj = arch_kernel_obj.PageTable x2\<rbrakk> \<Longrightarrow> is_real_cap cap
 3. \<And>a b aa arch_kernel_obj x3. \<lbrakk>transform_page_directory_contents x3 b = Some cap; asid \<in> cdl_cap_asid' cap; ref = (a, b); invs s; valid_list s; valid_sched s; a \<noteq> idle_thread s; kheap s a = Some (ArchObj (arch_kernel_obj.PageDirectory x3)); aa = ArchObj (arch_kernel_obj.PageDirectory x3); arch_kernel_obj = arch_kernel_obj.PageDirectory x3\<rbrakk> \<Longrightarrow> is_real_cap cap proof (prove)
goal (3 subgoals):
 1. \<And>a b x1. \<lbrakk>asid \<in> cdl_cap_asid' (transform_asid_pool_entry (x1 (word_of_nat b))); ref = (a, b); invs s; valid_list s; valid_sched s; a \<noteq> idle_thread s; kheap s a = Some (ArchObj (ASIDPool x1)); b < 1024; cap = transform_asid_pool_entry (x1 (word_of_nat b))\<rbrakk> \<Longrightarrow> is_real_cap (transform_asid_pool_entry (x1 (word_of_nat b)))
 2. \<And>a b aa arch_kernel_obj x2. \<lbrakk>transform_page_table_contents x2 b = Some cap; asid \<in> cdl_cap_asid' cap; ref = (a, b); invs s; valid_list s; valid_sched s; a \<noteq> idle_thread s; kheap s a = Some (ArchObj (arch_kernel_obj.PageTable x2)); aa = ArchObj (arch_kernel_obj.PageTable x2); arch_kernel_obj = arch_kernel_obj.PageTable x2\<rbrakk> \<Longrightarrow> is_real_cap cap
 3. \<And>a b aa arch_kernel_obj x3. \<lbrakk>transform_page_directory_contents x3 b = Some cap; asid \<in> cdl_cap_asid' cap; ref = (a, b); invs s; valid_list s; valid_sched s; a \<noteq> idle_thread s; kheap s a = Some (ArchObj (arch_kernel_obj.PageDirectory x3)); aa = ArchObj (arch_kernel_obj.PageDirectory x3); arch_kernel_obj = arch_kernel_obj.PageDirectory x3\<rbrakk> \<Longrightarrow> is_real_cap cap proof (prove)
goal (2 subgoals):
 1. \<And>a b aa arch_kernel_obj x2. \<lbrakk>transform_page_table_contents x2 b = Some cap; asid \<in> cdl_cap_asid' cap; ref = (a, b); invs s; valid_list s; valid_sched s; a \<noteq> idle_thread s; kheap s a = Some (ArchObj (arch_kernel_obj.PageTable x2)); aa = ArchObj (arch_kernel_obj.PageTable x2); arch_kernel_obj = arch_kernel_obj.PageTable x2\<rbrakk> \<Longrightarrow> is_real_cap cap
 2. \<And>a b aa arch_kernel_obj x3. \<lbrakk>transform_page_directory_contents x3 b = Some cap; asid \<in> cdl_cap_asid' cap; ref = (a, b); invs s; valid_list s; valid_sched s; a \<noteq> idle_thread s; kheap s a = Some (ArchObj (arch_kernel_obj.PageDirectory x3)); aa = ArchObj (arch_kernel_obj.PageDirectory x3); arch_kernel_obj = arch_kernel_obj.PageDirectory x3\<rbrakk> \<Longrightarrow> is_real_cap cap proof (prove)
goal (2 subgoals):
 1. \<And>a b x2. \<lbrakk>asid \<in> cdl_cap_asid' (transform_pte (x2 (word_of_nat b))); ref = (a, b); invs s; valid_list s; valid_sched s; a \<noteq> idle_thread s; kheap s a = Some (ArchObj (arch_kernel_obj.PageTable x2)); b < 256; cap = transform_pte (x2 (word_of_nat b))\<rbrakk> \<Longrightarrow> is_real_cap (transform_pte (x2 (word_of_nat b)))
 2. \<And>a b aa arch_kernel_obj x3. \<lbrakk>transform_page_directory_contents x3 b = Some cap; asid \<in> cdl_cap_asid' cap; ref = (a, b); invs s; valid_list s; valid_sched s; a \<noteq> idle_thread s; kheap s a = Some (ArchObj (arch_kernel_obj.PageDirectory x3)); aa = ArchObj (arch_kernel_obj.PageDirectory x3); arch_kernel_obj = arch_kernel_obj.PageDirectory x3\<rbrakk> \<Longrightarrow> is_real_cap cap proof (prove)
goal (1 subgoal):
 1. \<And>a b aa arch_kernel_obj x3. \<lbrakk>transform_page_directory_contents x3 b = Some cap; asid \<in> cdl_cap_asid' cap; ref = (a, b); invs s; valid_list s; valid_sched s; a \<noteq> idle_thread s; kheap s a = Some (ArchObj (arch_kernel_obj.PageDirectory x3)); aa = ArchObj (arch_kernel_obj.PageDirectory x3); arch_kernel_obj = arch_kernel_obj.PageDirectory x3\<rbrakk> \<Longrightarrow> is_real_cap cap proof (prove)
goal (1 subgoal):
 1. \<And>a b x3. \<lbrakk>asid \<in> cdl_cap_asid' (transform_pde (kernel_pde_mask x3 (word_of_nat b))); ref = (a, b); invs s; valid_list s; valid_sched s; a \<noteq> idle_thread s; kheap s a = Some (ArchObj (arch_kernel_obj.PageDirectory x3)); b < 4096; cap = transform_pde (kernel_pde_mask x3 (word_of_nat b))\<rbrakk> \<Longrightarrow> is_real_cap (transform_pde (kernel_pde_mask x3 (word_of_nat b))) proof (prove)
goal:
No subgoals!