riscv aspec: abbreviations for asid_table & pt table base + index

(moved from riscv ainvs)
This commit is contained in:
Gerwin Klein 2019-03-07 10:17:46 +11:00 committed by Rafal Kolanski
parent bdd9a3f1ea
commit a37d867e66
3 changed files with 18 additions and 21 deletions

View File

@ -1412,14 +1412,6 @@ lemma set_pt_invs:
apply (clarsimp simp: is_pt_cap_def cap_asid_def) apply (clarsimp simp: is_pt_cap_def cap_asid_def)
done *) done *)
(* FIXME RISCV: move to ASpec/ArchVSpaceAcc *)
locale_abbrev table_base :: "obj_ref \<Rightarrow> obj_ref" where
"table_base p \<equiv> p && ~~mask pt_bits"
(* FIXME RISCV: move to ASpec/ArchVSpaceAcc *)
locale_abbrev table_index :: "obj_ref \<Rightarrow> pt_index" where
"table_index p \<equiv> ucast (p && mask pt_bits >> pte_bits)"
lemma store_pte_invs: lemma store_pte_invs:
"\<lbrace>invs and (\<lambda>s. (\<forall>level. \<exists>\<rhd>(level, table_base p) s \<longrightarrow> valid_pte level pte s)) and (* potential off-by-one in level *) "\<lbrace>invs and (\<lambda>s. (\<forall>level. \<exists>\<rhd>(level, table_base p) s \<longrightarrow> valid_pte level pte s)) and (* potential off-by-one in level *)
K (wellformed_pte pte) and K (wellformed_pte pte) and

View File

@ -120,10 +120,6 @@ end_qualify
context Arch begin global_naming RISCV64 context Arch begin global_naming RISCV64
(* FIXME RISCV: move to ASpec *)
locale_abbrev
"asid_table \<equiv> \<lambda>s. riscv_asid_table (arch_state s)"
(* compatibility with other architectures, input only *) (* compatibility with other architectures, input only *)
abbreviation abbreviation
"vs_lookup s \<equiv> \<lambda>level asid vref. vs_lookup_table level asid vref s" "vs_lookup s \<equiv> \<lambda>level asid vref. vs_lookup_table level asid vref s"

View File

@ -37,6 +37,9 @@ definition asid_low_bits_of :: "asid \<Rightarrow> asid_low_index"
lemmas asid_bits_of_defs = asid_high_bits_of_def asid_low_bits_of_def lemmas asid_bits_of_defs = asid_high_bits_of_def asid_low_bits_of_def
locale_abbrev
"asid_table \<equiv> \<lambda>s. riscv_asid_table (arch_state s)"
section "Kernel Heap Accessors" section "Kernel Heap Accessors"
text \<open>Manipulate ASID pools, page directories and page tables in the kernel heap.\<close> text \<open>Manipulate ASID pools, page directories and page tables in the kernel heap.\<close>
@ -75,17 +78,23 @@ definition set_pt :: "obj_ref \<Rightarrow> (pt_index \<Rightarrow> pte) \<Right
set_object ptr (ArchObj (PageTable pt)) set_object ptr (ArchObj (PageTable pt))
od" od"
(* The base address of the table a page table entry at p is in (assuming alignment) *)
locale_abbrev table_base :: "obj_ref \<Rightarrow> obj_ref" where
"table_base p \<equiv> p && ~~mask pt_bits"
(* The index within the page table that a page table entry at p addresses *)
locale_abbrev table_index :: "obj_ref \<Rightarrow> pt_index" where
"table_index p \<equiv> ucast (p && mask pt_bits >> pte_bits)"
(* p is the address of the pte, (* p is the address of the pte,
which consists of base (for the pt) and offset (for the index inside the pt). which consists of base (for the pt) and offset (for the index inside the pt).
We avoid addresses between ptes. *) We assert that we avoid addresses between ptes. *)
definition pte_of :: "obj_ref \<Rightarrow> (obj_ref \<rightharpoonup> pt) \<rightharpoonup> pte" definition pte_of :: "obj_ref \<Rightarrow> (obj_ref \<rightharpoonup> pt) \<rightharpoonup> pte"
where where
"pte_of p \<equiv> do { "pte_of p \<equiv> do {
oassert (is_aligned p pte_bits); oassert (is_aligned p pte_bits);
let base = p && ~~mask pt_bits; pt \<leftarrow> oapply (table_base p);
let index = (p && mask pt_bits) >> pte_bits; oreturn $ pt (table_index p)
pt \<leftarrow> oapply base;
oreturn $ pt (ucast index)
}" }"
locale_abbrev ptes_of :: "'z::state_ext state \<Rightarrow> obj_ref \<rightharpoonup> pte" locale_abbrev ptes_of :: "'z::state_ext state \<Rightarrow> obj_ref \<rightharpoonup> pte"
@ -101,10 +110,10 @@ definition store_pte :: "obj_ref \<Rightarrow> pte \<Rightarrow> (unit,'z::state
where where
"store_pte p pte \<equiv> do "store_pte p pte \<equiv> do
assert (is_aligned p pte_bits); assert (is_aligned p pte_bits);
base \<leftarrow> return $ p && ~~mask pt_bits; base \<leftarrow> return $ table_base p;
index \<leftarrow> return $ (p && mask pt_bits) >> pte_bits; index \<leftarrow> return $ table_index p;
pt \<leftarrow> get_pt base; pt \<leftarrow> get_pt (table_base p);
pt' \<leftarrow> return $ pt (ucast index := pte); pt' \<leftarrow> return $ pt (index := pte);
set_pt base pt' set_pt base pt'
od" od"