From 91c3fda00badedb7d144fc41757f93f95a54ca92 Mon Sep 17 00:00:00 2001 From: Mark Johnston Date: Tue, 5 Mar 2019 23:56:40 +0000 Subject: [PATCH] Add pmap_get_tables() for riscv. This mirrors the arm64 implementation and is for use in the minidump code. Submitted by: Mitchell Horne Differential Revision: https://reviews.freebsd.org/D18321 --- sys/riscv/riscv/pmap.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/sys/riscv/riscv/pmap.c b/sys/riscv/riscv/pmap.c index d25224f75e79..a4e5bb29da7f 100644 --- a/sys/riscv/riscv/pmap.c +++ b/sys/riscv/riscv/pmap.c @@ -4438,3 +4438,40 @@ pmap_is_valid_memattr(pmap_t pmap __unused, vm_memattr_t mode) return (mode >= VM_MEMATTR_DEVICE && mode <= VM_MEMATTR_WRITE_BACK); } + +bool +pmap_get_tables(pmap_t pmap, vm_offset_t va, pd_entry_t **l1, pd_entry_t **l2, + pt_entry_t **l3) +{ + pd_entry_t *l1p, *l2p; + + /* Get l1 directory entry. */ + l1p = pmap_l1(pmap, va); + *l1 = l1p; + + if (l1p == NULL || (pmap_load(l1p) & PTE_V) == 0) + return (false); + + if ((pmap_load(l1p) & PTE_RX) != 0) { + *l2 = NULL; + *l3 = NULL; + return (true); + } + + /* Get l2 directory entry. */ + l2p = pmap_l1_to_l2(l1p, va); + *l2 = l2p; + + if (l2p == NULL || (pmap_load(l2p) & PTE_V) == 0) + return (false); + + if ((pmap_load(l2p) & PTE_RX) != 0) { + *l3 = NULL; + return (true); + } + + /* Get l3 page table entry. */ + *l3 = pmap_l2_to_l3(l2p, va); + + return (true); +}