+define _pmap_walk_arm_level1_section
+ set $kgm_tte_p = $arg0
+ set $kgm_tte = *$kgm_tte_p
+ set $kgm_vaddr = $arg1
+
+ # Supersection or just section?
+ if (($kgm_tte & 0x00040000) == 0x00040000)
+ set $kgm_paddr = ($kgm_tte & 0xFF000000) | ($kgm_vaddr & 0x00FFFFFF)
+ set $kgm_paddr_isvalid = 1
+ else
+ set $kgm_paddr = ($kgm_tte & 0xFFF00000) | ($kgm_vaddr & 0x000FFFFF)
+ set $kgm_paddr_isvalid = 1
+ end
+
+ if $kgm_pt_verbose >= 2
+ printf "0x%08x\n\t0x%08x\n\t", (unsigned long)$kgm_tte_p, $kgm_tte
+
+ # bit [1:0] evaluated in _pmap_walk_arm
+
+ # B bit 2
+ set $kgm_b_bit = (($kgm_tte & 0x00000004) >> 2)
+
+ # C bit 3
+ set $kgm_c_bit = (($kgm_tte & 0x00000008) >> 3)
+
+ # XN bit 4
+ if ($kgm_tte & 0x00000010)
+ printf "no-execute"
+ else
+ printf "execute"
+ end
+
+ # Domain bit [8:5] if not supersection
+ if (($kgm_tte & 0x00040000) == 0x00000000)
+ printf " domain(%d)", (($kgm_tte & 0x000001e0) >> 5)
+ end
+
+ # IMP bit 9
+ printf " imp(%d)", (($kgm_tte & 0x00000200) >> 9)
+
+ # AP bit 15 and [11:10], merged to a single 3-bit value
+ set $kgm_access = (($kgm_tte & 0x00000c00) >> 10) | (($kgm_tte & 0x00008000) >> 13)
+ if ($kgm_access == 0x0)
+ printf " noaccess"
+ end
+ if ($kgm_access == 0x1)
+ printf " supervisor(readwrite) user(noaccess)"
+ end
+ if ($kgm_access == 0x2)
+ printf " supervisor(readwrite) user(readonly)"
+ end
+ if ($kgm_access == 0x3)
+ printf " supervisor(readwrite) user(readwrite)"
+ end
+ if ($kgm_access == 0x4)
+ printf " noaccess(reserved)"
+ end
+ if ($kgm_access == 0x5)
+ printf " supervisor(readonly) user(noaccess)"
+ end
+ if ($kgm_access == 0x6)
+ printf " supervisor(readonly) user(readonly)"
+ end
+ if ($kgm_access == 0x7)
+ printf " supervisor(readonly) user(readonly)"
+ end
+
+ # TEX bit [14:12]
+ set $kgm_tex_bits = (($kgm_tte & 0x00007000) >> 12)
+
+ # Print TEX, C, B all together
+ printf " TEX:C:B(%d%d%d:%d:%d)", ($kgm_tex_bits & 0x4 ? 1 : 0), ($kgm_tex_bits & 0x2 ? 1 : 0), ($kgm_tex_bits & 0x1 ? 1 : 0), $kgm_c_bit, $kgm_b_bit
+
+ # S bit 16
+ if ($kgm_tte & 0x00010000)
+ printf " shareable"
+ else
+ printf " not-shareable"
+ end
+
+ # nG bit 17
+ if ($kgm_tte & 0x00020000)
+ printf " not-global"
+ else
+ printf " global"
+ end
+
+ # Supersection bit 18
+ if ($kgm_tte & 0x00040000)
+ printf " supersection"
+ else
+ printf " section"
+ end
+
+ # NS bit 19
+ if ($kgm_tte & 0x00080000)
+ printf " no-secure"
+ else
+ printf " secure"
+ end
+
+ printf "\n"
+ end
+end
+
+define _pmap_walk_arm_level2
+ set $kgm_tte_p = $arg0
+ set $kgm_tte = *$kgm_tte_p
+ set $kgm_vaddr = $arg1
+
+ set $kgm_pte_pbase = (($kgm_tte & 0xFFFFFC00) - gPhysBase + gVirtBase)
+ set $kgm_pte_index = ($kgm_vaddr >> 12) & 0x000000FF
+ set $kgm_pte_p = &((pt_entry_t *)$kgm_pte_pbase)[$kgm_pte_index]
+ set $kgm_pte = *$kgm_pte_p
+
+ # Print first level symbolically
+ if $kgm_pt_verbose >= 2
+ printf "0x%08x\n\t0x%08x\n\t", (unsigned long)$kgm_tte_p, $kgm_tte
+
+ # bit [1:0] evaluated in _pmap_walk_arm
+
+ # NS bit 3
+ if ($kgm_tte & 0x00000008)
+ printf "no-secure"
+ else
+ printf "secure"
+ end
+
+ # Domain bit [8:5]
+ printf " domain(%d)", (($kgm_tte & 0x000001e0) >> 5)
+
+ # IMP bit 9
+ printf " imp(%d)", (($kgm_tte & 0x00000200) >> 9)
+
+ printf "\n"
+ end
+
+ if $kgm_pt_verbose >= 2
+ printf "second-level table (index %d):\n", $kgm_pte_index
+ end
+ if $kgm_pt_verbose >= 3
+ set $kgm_pte_loop = 0
+ while $kgm_pte_loop < 256
+ set $kgm_pte_p_tmp = &((pt_entry_t *)$kgm_pte_pbase)[$kgm_pte_loop]
+ printf "0x%08x:\t0x%08x\n", (unsigned long)$kgm_pte_p_tmp, *$kgm_pte_p_tmp
+ set $kgm_pte_loop = $kgm_pte_loop + 1
+ end
+ end
+
+ if ($kgm_pte & 0x00000003)
+ set $kgm_pve_p = (pv_entry_t *)($kgm_pte_pbase + 0x100*sizeof(pt_entry_t) + $kgm_pte_index*sizeof(pv_entry_t))
+ if ($kgm_pve_p->shadow != 0)
+ set $kgm_spte = $kgm_pve_p->shadow ^ ($kgm_vaddr & ~0xFFF)
+ set $kgm_paddr = ($kgm_spte & 0xFFFFF000) | ($kgm_vaddr & 0xFFF)
+ set $kgm_paddr_isvalid = 1
+ else
+ set $kgm_paddr = (*$kgm_pte_p & 0xFFFFF000) | ($kgm_vaddr & 0xFFF)
+ set $kgm_paddr_isvalid = 1
+ end
+ else
+ set $kgm_paddr = 0
+ set $kgm_paddr_isvalid = 0
+ end
+
+ if $kgm_pt_verbose >= 2
+ printf "0x%08x\n\t0x%08x\n\t", (unsigned long)$kgm_pte_p, $kgm_pte
+ if (($kgm_pte & 0x00000003) == 0x00000000)
+ printf "invalid"
+ else
+ if (($kgm_pte & 0x00000003) == 0x00000001)
+ printf "large"
+
+ # XN bit 15
+ if ($kgm_pte & 0x00008000) == 0x00008000
+ printf " no-execute"
+ else
+ printf " execute"
+ end
+ else
+ printf "small"
+
+ # XN bit 0
+ if ($kgm_pte & 0x00000001) == 0x00000001
+ printf " no-execute"
+ else
+ printf " execute"
+ end
+ end
+
+ # B bit 2
+ set $kgm_b_bit = (($kgm_pte & 0x00000004) >> 2)
+
+ # C bit 3
+ set $kgm_c_bit = (($kgm_pte & 0x00000008) >> 3)
+
+ # AP bit 9 and [5:4], merged to a single 3-bit value
+ set $kgm_access = (($kgm_pte & 0x00000030) >> 4) | (($kgm_pte & 0x00000200) >> 7)
+ if ($kgm_access == 0x0)
+ printf " noaccess"
+ end
+ if ($kgm_access == 0x1)
+ printf " supervisor(readwrite) user(noaccess)"
+ end
+ if ($kgm_access == 0x2)
+ printf " supervisor(readwrite) user(readonly)"
+ end
+ if ($kgm_access == 0x3)
+ printf " supervisor(readwrite) user(readwrite)"
+ end
+ if ($kgm_access == 0x4)
+ printf " noaccess(reserved)"
+ end
+ if ($kgm_access == 0x5)
+ printf " supervisor(readonly) user(noaccess)"
+ end
+ if ($kgm_access == 0x6)
+ printf " supervisor(readonly) user(readonly)"
+ end
+ if ($kgm_access == 0x7)
+ printf " supervisor(readonly) user(readonly)"
+ end
+
+ # TEX bit [14:12] for large, [8:6] for small
+ if (($kgm_pte & 0x00000003) == 0x00000001)
+ set $kgm_tex_bits = (($kgm_pte & 0x00007000) >> 12)
+ else
+ set $kgm_tex_bits = (($kgm_pte & 0x000001c0) >> 6)
+ end
+
+ # Print TEX, C, B all together
+ printf " TEX:C:B(%d%d%d:%d:%d)", ($kgm_tex_bits & 0x4 ? 1 : 0), ($kgm_tex_bits & 0x2 ? 1 : 0), ($kgm_tex_bits & 0x1 ? 1 : 0), $kgm_c_bit, $kgm_b_bit
+
+ # S bit 10
+ if ($kgm_pte & 0x00000400)
+ printf " shareable"
+ else
+ printf " not-shareable"
+ end
+
+ # nG bit 11
+ if ($kgm_pte & 0x00000800)
+ printf " not-global"
+ else
+ printf " global"
+ end
+
+ end
+ printf "\n"
+ end
+end
+
+# See ARM ARM Section B3.3