[riscv-pmp] Pmp_hart_has_privs local variable name easily misunderstood
Goal
The s
and e
local variable in function target/riscv/pmp.c:pmp_hart_has_privs
can be easily misunderstood
Technical details
https://gitlab.com/qemu-project/qemu/-/blob/master/target/riscv/pmp.c#L295-L296
s
represents whether start address is in pmp_range
e
represents whether end address is in pmp_range
The name and type of them can be easily misunderstood.
These modifications will improve code readability and accuracy.
- consider change it to
sa_in
andea_in
with type bool. - change
pmp_is_in_range
return value type to bool - replace partially inside condition with
sa_in ^ ea_in
- replace fully inside condition with
sa_in && ea_in
Additional information
// int => bool
static int pmp_is_in_range(CPURISCVState *env, int pmp_index,
target_ulong addr);
bool pmp_hart_has_privs(CPURISCVState *env, target_ulong addr,
target_ulong size, pmp_priv_t privs,
pmp_priv_t *allowed_privs, target_ulong mode)
{
int i = 0;
int pmp_size = 0;
// easily misunderstood local variable
target_ulong s = 0;
target_ulong e = 0;
for (i = 0; i < MAX_RISCV_PMPS; i++) {
s = pmp_is_in_range(env, i, addr);
e = pmp_is_in_range(env, i, addr + pmp_size - 1);
/* partially inside */
if ((s + e) == 1) {
}
/* fully inside */
if ((s + e) == 2) {