Skip to content

Commit 504dcda

Browse files
loiclefortMichael Tokarev
authored andcommitted
target/riscv: pmp: move Smepmp operation conversion into a function
Signed-off-by: Loïc Lefort <[email protected]> Reviewed-by: Daniel Henrique Barboza <[email protected]> Reviewed-by: Alistair Francis <[email protected]> Reviewed-by: LIU Zhiwei <[email protected]> Message-ID: <[email protected]> Signed-off-by: Alistair Francis <[email protected]> Cc: [email protected] (cherry picked from commit 915b203) Signed-off-by: Michael Tokarev <[email protected]>
1 parent f82dd28 commit 504dcda

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

target/riscv/pmp.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@ static bool pmp_write_cfg(CPURISCVState *env, uint32_t addr_index,
3131
uint8_t val);
3232
static uint8_t pmp_read_cfg(CPURISCVState *env, uint32_t addr_index);
3333

34+
/*
35+
* Convert the PMP permissions to match the truth table in the Smepmp spec.
36+
*/
37+
static inline uint8_t pmp_get_smepmp_operation(uint8_t cfg)
38+
{
39+
return ((cfg & PMP_LOCK) >> 4) | ((cfg & PMP_READ) << 2) |
40+
(cfg & PMP_WRITE) | ((cfg & PMP_EXEC) >> 2);
41+
}
42+
3443
/*
3544
* Accessor method to extract address matching type 'a field' from cfg reg
3645
*/
@@ -355,16 +364,6 @@ bool pmp_hart_has_privs(CPURISCVState *env, hwaddr addr,
355364
const uint8_t a_field =
356365
pmp_get_a_field(env->pmp_state.pmp[i].cfg_reg);
357366

358-
/*
359-
* Convert the PMP permissions to match the truth table in the
360-
* Smepmp spec.
361-
*/
362-
const uint8_t smepmp_operation =
363-
((env->pmp_state.pmp[i].cfg_reg & PMP_LOCK) >> 4) |
364-
((env->pmp_state.pmp[i].cfg_reg & PMP_READ) << 2) |
365-
(env->pmp_state.pmp[i].cfg_reg & PMP_WRITE) |
366-
((env->pmp_state.pmp[i].cfg_reg & PMP_EXEC) >> 2);
367-
368367
if (((s + e) == 2) && (PMP_AMATCH_OFF != a_field)) {
369368
/*
370369
* If the PMP entry is not off and the address is in range,
@@ -383,6 +382,9 @@ bool pmp_hart_has_privs(CPURISCVState *env, hwaddr addr,
383382
/*
384383
* If mseccfg.MML Bit set, do the enhanced pmp priv check
385384
*/
385+
const uint8_t smepmp_operation =
386+
pmp_get_smepmp_operation(env->pmp_state.pmp[i].cfg_reg);
387+
386388
if (mode == PRV_M) {
387389
switch (smepmp_operation) {
388390
case 0:

0 commit comments

Comments
 (0)