Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions arch/riscv/core/pmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,20 +168,35 @@ static inline void z_riscv_pmp_write_config(unsigned long *pmp_cfg, size_t pmp_c
#endif
}

static void dump_pmp_regs(const char *banner)
/**
* @brief Reads the PMP address CSRs (pmpaddrX) for all configured slots.
*
* This helper function abstracts the iterative logic required to read the
* individual PMP address registers (pmpaddr0, pmpaddr1, ..., pmpaddrN)
* up to the total number of PMP slots configured by CONFIG_PMP_SLOTS.
*
* @param pmp_addr Pointer to the array where the CSR contents will be stored.
* @param pmp_addr_size The size of the pmp_addr array, measured in unsigned long entries.
*/
static inline void z_riscv_pmp_read_addr(unsigned long *pmp_addr, size_t pmp_addr_size)
{
unsigned long pmp_addr[CONFIG_PMP_SLOTS];
unsigned long pmp_cfg[CONFIG_PMP_SLOTS / PMPCFG_STRIDE];
__ASSERT(pmp_addr_size == (size_t)(CONFIG_PMP_SLOTS), "PMP address array size mismatch");

#define PMPADDR_READ(x) pmp_addr[x] = csr_read(pmpaddr##x)

FOR_EACH(PMPADDR_READ, (;), 0, 1, 2, 3, 4, 5, 6, 7);

#if CONFIG_PMP_SLOTS > 8
FOR_EACH(PMPADDR_READ, (;), 8, 9, 10, 11, 12, 13, 14, 15);
#endif

#undef PMPADDR_READ
}

static void dump_pmp_regs(const char *banner)
{
unsigned long pmp_addr[CONFIG_PMP_SLOTS];
unsigned long pmp_cfg[CONFIG_PMP_SLOTS / PMPCFG_STRIDE];

z_riscv_pmp_read_addr(pmp_addr, (size_t)(CONFIG_PMP_SLOTS));
z_riscv_pmp_read_config(pmp_cfg, (size_t)(CONFIG_PMP_SLOTS / PMPCFG_STRIDE));
print_pmp_entries(0, CONFIG_PMP_SLOTS, pmp_addr, pmp_cfg, banner);
}
Expand Down
Loading