@@ -31,6 +31,15 @@ static bool pmp_write_cfg(CPURISCVState *env, uint32_t addr_index,
31
31
uint8_t val );
32
32
static uint8_t pmp_read_cfg (CPURISCVState * env , uint32_t addr_index );
33
33
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
+
34
43
/*
35
44
* Accessor method to extract address matching type 'a field' from cfg reg
36
45
*/
@@ -355,16 +364,6 @@ bool pmp_hart_has_privs(CPURISCVState *env, hwaddr addr,
355
364
const uint8_t a_field =
356
365
pmp_get_a_field (env -> pmp_state .pmp [i ].cfg_reg );
357
366
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
-
368
367
if (((s + e ) == 2 ) && (PMP_AMATCH_OFF != a_field )) {
369
368
/*
370
369
* 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,
383
382
/*
384
383
* If mseccfg.MML Bit set, do the enhanced pmp priv check
385
384
*/
385
+ const uint8_t smepmp_operation =
386
+ pmp_get_smepmp_operation (env -> pmp_state .pmp [i ].cfg_reg );
387
+
386
388
if (mode == PRV_M ) {
387
389
switch (smepmp_operation ) {
388
390
case 0 :
0 commit comments