theory Ipc_AI

lemma transfer_caps_loop_valid_globals [wp]:
  "\<And>slots caps ep buffer n mi.
    \<lbrace>valid_global_refs and valid_objs and valid_mdb and K (distinct slots)
       and (\<lambda>s::'state_ext state. \<forall>slot \<in> set slots. real_cte_at slot s
                                  \<and> cte_wp_at (\<lambda>cap. cap = cap.NullCap) slot s)
       and transfer_caps_srcs caps\<rbrace>
      transfer_caps_loop ep buffer n caps slots mi
    \<lbrace>\<lambda>rv. valid_global_refs\<rbrace>" apply (rule hoare_pre) apply (rule transfer_caps_loop_presM[where em=False and ex=False and vo=True]) apply (wp | simp)+ apply (clarsimp simp: cte_wp_at_caps_of_state is_derived_cap_range) apply (wp valid_global_refs_cte_lift|simp|intro conjI ballI)+ apply (clarsimp simp:cte_wp_at_caps_of_state) apply (drule(1) bspec,clarsimp) apply (frule(1) caps_of_state_valid) apply (fastforce simp:valid_cap_def) apply clarsimp apply (drule(1) bspec) apply (clarsimp simp:cte_wp_at_caps_of_state) done

(* Proof state trace *)
proof (prove)
goal (1 subgoal):
 1. \<And>slots caps ep buffer n mi. \<lbrace>valid_global_refs and valid_objs and valid_mdb and K (distinct slots) and (\<lambda>s. \<forall>slot\<in>set slots. real_cte_at slot s \<and> cte_wp_at (\<lambda>cap. cap = NullCap) slot s) and (\<lambda>s. \<forall>x\<in>set caps. cte_wp_at (\<lambda>cp. fst x \<noteq> NullCap \<longrightarrow> cp = fst x) (snd x) s \<and> real_cte_at (snd x) s)\<rbrace> transfer_caps_loop ep buffer n caps slots mi \<lbrace>\<lambda>rv. valid_global_refs\<rbrace> proof (prove)
goal (2 subgoals):
 1. \<And>slots caps ep buffer n mi. \<lbrace>?Q slots caps ep buffer n mi\<rbrace> transfer_caps_loop ep buffer n caps slots mi \<lbrace>\<lambda>rv. valid_global_refs\<rbrace>
 2. \<And>slots caps ep buffer n mi s. (valid_global_refs and valid_objs and valid_mdb and K (distinct slots) and (\<lambda>s. \<forall>slot\<in>set slots. real_cte_at slot s \<and> cte_wp_at (\<lambda>cap. cap = NullCap) slot s) and (\<lambda>s. \<forall>x\<in>set caps. cte_wp_at (\<lambda>cp. fst x \<noteq> NullCap \<longrightarrow> cp = fst x) (snd x) s \<and> real_cte_at (snd x) s)) s \<Longrightarrow> ?Q slots caps ep buffer n mi s proof (prove)
goal (3 subgoals):
 1. \<And>slots caps ep buffer n mi cap src dest. \<lbrace>\<lambda>s. valid_global_refs s \<and> (True \<longrightarrow> valid_objs s \<and> valid_mdb s \<and> real_cte_at dest s \<and> s \<turnstile> cap \<and> tcb_cap_valid cap dest s \<and> real_cte_at src s \<and> cte_wp_at (is_derived (cdt s) src cap) src s \<and> cap \<noteq> NullCap) \<and> (False \<longrightarrow> cte_wp_at ((=) NullCap) dest s) \<and> (False \<longrightarrow> ex_cte_cap_wp_to (appropriate_cte_cap cap) dest s)\<rbrace> cap_insert cap src dest \<lbrace>\<lambda>rv. valid_global_refs\<rbrace>
 2. \<And>slots caps ep buffer n mi b na. \<lbrace>valid_global_refs\<rbrace> set_extra_badge buffer b na \<lbrace>\<lambda>_. valid_global_refs\<rbrace>
 3. \<And>slots caps ep buffer n mi s. (valid_global_refs and valid_objs and valid_mdb and K (distinct slots) and (\<lambda>s. \<forall>slot\<in>set slots. real_cte_at slot s \<and> cte_wp_at (\<lambda>cap. cap = NullCap) slot s) and (\<lambda>s. \<forall>x\<in>set caps. cte_wp_at (\<lambda>cp. fst x \<noteq> NullCap \<longrightarrow> cp = fst x) (snd x) s \<and> real_cte_at (snd x) s)) s \<Longrightarrow> valid_global_refs s \<and> (True \<longrightarrow> valid_objs s \<and> valid_mdb s \<and> distinct slots \<and> (\<forall>x\<in>set slots. cte_wp_at (\<lambda>cap. cap = NullCap) x s \<and> real_cte_at x s) \<and> (\<forall>x\<in>set caps. s \<turnstile> fst x \<and> cte_wp_at (\<lambda>cp. fst x \<noteq> NullCap \<longrightarrow> cp \<noteq> fst x \<longrightarrow> cp = masked_as_full (fst x) (fst x)) (snd x) s \<and> real_cte_at (snd x) s)) \<and> (False \<longrightarrow> (\<forall>x\<in>set slots. ex_cte_cap_wp_to is_cnode_cap x s)) proof (prove)
goal (3 subgoals):
 1. \<And>cap src dest s. valid_global_refs s \<and> valid_objs s \<and> valid_mdb s \<and> real_cte_at dest s \<and> s \<turnstile> cap \<and> tcb_cap_valid cap dest s \<and> real_cte_at src s \<and> cte_wp_at (is_derived (cdt s) src cap) src s \<and> cap \<noteq> NullCap \<Longrightarrow> cte_wp_at (\<lambda>scap. cap_range cap \<subseteq> cap_range scap) src s
 2. \<And>slots caps ep buffer n mi b na. \<lbrace>valid_global_refs\<rbrace> set_extra_badge buffer b na \<lbrace>\<lambda>_. valid_global_refs\<rbrace>
 3. \<And>slots caps ep buffer n mi s. (valid_global_refs and valid_objs and valid_mdb and K (distinct slots) and (\<lambda>s. \<forall>slot\<in>set slots. real_cte_at slot s \<and> cte_wp_at (\<lambda>cap. cap = NullCap) slot s) and (\<lambda>s. \<forall>x\<in>set caps. cte_wp_at (\<lambda>cp. fst x \<noteq> NullCap \<longrightarrow> cp = fst x) (snd x) s \<and> real_cte_at (snd x) s)) s \<Longrightarrow> valid_global_refs s \<and> (True \<longrightarrow> valid_objs s \<and> valid_mdb s \<and> distinct slots \<and> (\<forall>x\<in>set slots. cte_wp_at (\<lambda>cap. cap = NullCap) x s \<and> real_cte_at x s) \<and> (\<forall>x\<in>set caps. s \<turnstile> fst x \<and> cte_wp_at (\<lambda>cp. fst x \<noteq> NullCap \<longrightarrow> cp \<noteq> fst x \<longrightarrow> cp = masked_as_full (fst x) (fst x)) (snd x) s \<and> real_cte_at (snd x) s)) \<and> (False \<longrightarrow> (\<forall>x\<in>set slots. ex_cte_cap_wp_to is_cnode_cap x s)) proof (prove)
goal (2 subgoals):
 1. \<And>slots caps ep buffer n mi b na. \<lbrace>valid_global_refs\<rbrace> set_extra_badge buffer b na \<lbrace>\<lambda>_. valid_global_refs\<rbrace>
 2. \<And>slots caps ep buffer n mi s. (valid_global_refs and valid_objs and valid_mdb and K (distinct slots) and (\<lambda>s. \<forall>slot\<in>set slots. real_cte_at slot s \<and> cte_wp_at (\<lambda>cap. cap = NullCap) slot s) and (\<lambda>s. \<forall>x\<in>set caps. cte_wp_at (\<lambda>cp. fst x \<noteq> NullCap \<longrightarrow> cp = fst x) (snd x) s \<and> real_cte_at (snd x) s)) s \<Longrightarrow> valid_global_refs s \<and> (True \<longrightarrow> valid_objs s \<and> valid_mdb s \<and> distinct slots \<and> (\<forall>x\<in>set slots. cte_wp_at (\<lambda>cap. cap = NullCap) x s \<and> real_cte_at x s) \<and> (\<forall>x\<in>set caps. s \<turnstile> fst x \<and> cte_wp_at (\<lambda>cp. fst x \<noteq> NullCap \<longrightarrow> cp \<noteq> fst x \<longrightarrow> cp = masked_as_full (fst x) (fst x)) (snd x) s \<and> real_cte_at (snd x) s)) \<and> (False \<longrightarrow> (\<forall>x\<in>set slots. ex_cte_cap_wp_to is_cnode_cap x s)) proof (prove)
goal (2 subgoals):
 1. \<And>slots caps s x. \<lbrakk>valid_global_refs s \<and> valid_objs s \<and> valid_mdb s \<and> distinct slots \<and> (\<forall>slot\<in>set slots. real_cte_at slot s \<and> cte_wp_at (\<lambda>cap. cap = NullCap) slot s) \<and> (\<forall>x\<in>set caps. cte_wp_at (\<lambda>cp. fst x \<noteq> NullCap \<longrightarrow> cp = fst x) (snd x) s \<and> real_cte_at (snd x) s); x \<in> set caps\<rbrakk> \<Longrightarrow> s \<turnstile> fst x
 2. \<And>slots caps s x. \<lbrakk>valid_global_refs s \<and> valid_objs s \<and> valid_mdb s \<and> distinct slots \<and> (\<forall>slot\<in>set slots. real_cte_at slot s \<and> cte_wp_at (\<lambda>cap. cap = NullCap) slot s) \<and> (\<forall>x\<in>set caps. cte_wp_at (\<lambda>cp. fst x \<noteq> NullCap \<longrightarrow> cp = fst x) (snd x) s \<and> real_cte_at (snd x) s); x \<in> set caps\<rbrakk> \<Longrightarrow> cte_wp_at (\<lambda>cp. fst x \<noteq> NullCap \<longrightarrow> cp \<noteq> fst x \<longrightarrow> cp = masked_as_full (fst x) (fst x)) (snd x) s proof (prove)
goal (2 subgoals):
 1. \<And>slots caps s a aa b. \<lbrakk>(a, aa, b) \<in> set caps; valid_global_refs s; valid_objs s; valid_mdb s; distinct slots; \<forall>slot\<in>set slots. real_cte_at slot s \<and> caps_of_state s slot = Some NullCap; \<forall>x\<in>set caps. (\<exists>cap. caps_of_state s (snd x) = Some cap \<and> (fst x \<noteq> NullCap \<longrightarrow> cap = fst x)) \<and> real_cte_at (snd x) s\<rbrakk> \<Longrightarrow> s \<turnstile> a
 2. \<And>slots caps s x. \<lbrakk>valid_global_refs s \<and> valid_objs s \<and> valid_mdb s \<and> distinct slots \<and> (\<forall>slot\<in>set slots. real_cte_at slot s \<and> cte_wp_at (\<lambda>cap. cap = NullCap) slot s) \<and> (\<forall>x\<in>set caps. cte_wp_at (\<lambda>cp. fst x \<noteq> NullCap \<longrightarrow> cp = fst x) (snd x) s \<and> real_cte_at (snd x) s); x \<in> set caps\<rbrakk> \<Longrightarrow> cte_wp_at (\<lambda>cp. fst x \<noteq> NullCap \<longrightarrow> cp \<noteq> fst x \<longrightarrow> cp = masked_as_full (fst x) (fst x)) (snd x) s proof (prove)
goal (2 subgoals):
 1. \<And>slots caps s a aa b cap. \<lbrakk>(a, aa, b) \<in> set caps; valid_global_refs s; valid_objs s; valid_mdb s; distinct slots; \<forall>slot\<in>set slots. real_cte_at slot s \<and> caps_of_state s slot = Some NullCap; cap_table_at (length b) aa s; caps_of_state s (aa, b) = Some cap; a \<noteq> NullCap \<longrightarrow> cap = a\<rbrakk> \<Longrightarrow> s \<turnstile> a
 2. \<And>slots caps s x. \<lbrakk>valid_global_refs s \<and> valid_objs s \<and> valid_mdb s \<and> distinct slots \<and> (\<forall>slot\<in>set slots. real_cte_at slot s \<and> cte_wp_at (\<lambda>cap. cap = NullCap) slot s) \<and> (\<forall>x\<in>set caps. cte_wp_at (\<lambda>cp. fst x \<noteq> NullCap \<longrightarrow> cp = fst x) (snd x) s \<and> real_cte_at (snd x) s); x \<in> set caps\<rbrakk> \<Longrightarrow> cte_wp_at (\<lambda>cp. fst x \<noteq> NullCap \<longrightarrow> cp \<noteq> fst x \<longrightarrow> cp = masked_as_full (fst x) (fst x)) (snd x) s proof (prove)
goal (2 subgoals):
 1. \<And>slots caps s a aa b cap. \<lbrakk>(a, aa, b) \<in> set caps; valid_global_refs s; valid_objs s; valid_mdb s; distinct slots; \<forall>slot\<in>set slots. real_cte_at slot s \<and> caps_of_state s slot = Some NullCap; cap_table_at (length b) aa s; caps_of_state s (aa, b) = Some cap; a \<noteq> NullCap \<longrightarrow> cap = a; s \<turnstile> cap\<rbrakk> \<Longrightarrow> s \<turnstile> a
 2. \<And>slots caps s x. \<lbrakk>valid_global_refs s \<and> valid_objs s \<and> valid_mdb s \<and> distinct slots \<and> (\<forall>slot\<in>set slots. real_cte_at slot s \<and> cte_wp_at (\<lambda>cap. cap = NullCap) slot s) \<and> (\<forall>x\<in>set caps. cte_wp_at (\<lambda>cp. fst x \<noteq> NullCap \<longrightarrow> cp = fst x) (snd x) s \<and> real_cte_at (snd x) s); x \<in> set caps\<rbrakk> \<Longrightarrow> cte_wp_at (\<lambda>cp. fst x \<noteq> NullCap \<longrightarrow> cp \<noteq> fst x \<longrightarrow> cp = masked_as_full (fst x) (fst x)) (snd x) s proof (prove)
goal (1 subgoal):
 1. \<And>slots caps s x. \<lbrakk>valid_global_refs s \<and> valid_objs s \<and> valid_mdb s \<and> distinct slots \<and> (\<forall>slot\<in>set slots. real_cte_at slot s \<and> cte_wp_at (\<lambda>cap. cap = NullCap) slot s) \<and> (\<forall>x\<in>set caps. cte_wp_at (\<lambda>cp. fst x \<noteq> NullCap \<longrightarrow> cp = fst x) (snd x) s \<and> real_cte_at (snd x) s); x \<in> set caps\<rbrakk> \<Longrightarrow> cte_wp_at (\<lambda>cp. fst x \<noteq> NullCap \<longrightarrow> cp \<noteq> fst x \<longrightarrow> cp = masked_as_full (fst x) (fst x)) (snd x) s proof (prove)
goal (1 subgoal):
 1. \<And>slots caps s a aa b. \<lbrakk>(a, aa, b) \<in> set caps; valid_global_refs s; valid_objs s; valid_mdb s; distinct slots; \<forall>slot\<in>set slots. real_cte_at slot s \<and> cte_wp_at (\<lambda>cap. cap = NullCap) slot s; \<forall>x\<in>set caps. cte_wp_at (\<lambda>cp. fst x \<noteq> NullCap \<longrightarrow> cp = fst x) (snd x) s \<and> real_cte_at (snd x) s\<rbrakk> \<Longrightarrow> cte_wp_at (\<lambda>cp. a \<noteq> NullCap \<longrightarrow> cp \<noteq> a \<longrightarrow> cp = masked_as_full a a) (aa, b) s proof (prove)
goal (1 subgoal):
 1. \<And>slots caps s a aa b. \<lbrakk>(a, aa, b) \<in> set caps; valid_global_refs s; valid_objs s; valid_mdb s; distinct slots; \<forall>slot\<in>set slots. real_cte_at slot s \<and> cte_wp_at (\<lambda>cap. cap = NullCap) slot s; cte_wp_at (\<lambda>cp. fst (a, aa, b) \<noteq> NullCap \<longrightarrow> cp = fst (a, aa, b)) (snd (a, aa, b)) s \<and> real_cte_at (snd (a, aa, b)) s\<rbrakk> \<Longrightarrow> cte_wp_at (\<lambda>cp. a \<noteq> NullCap \<longrightarrow> cp \<noteq> a \<longrightarrow> cp = masked_as_full a a) (aa, b) s proof (prove)
goal:
No subgoals!