On 10/14/25 1:34 PM, Anton Johansson wrote:
 From my understanding the upper_half argument only indicates whether the
upper or lower 32 bits should be returned, and upper_half will only ever
be set when MXLEN == 32.  However, the function also uses upper_half to
determine whether the inhibit flags are located in mcyclecfgh or
mcyclecfg, but this misses the case where MXLEN == 32, upper_half == false
for TARGET_RISCV32 where we would also need to read the upper half field.

Minor simplifications are also made along with some formatting fixes.

Signed-off-by: Anton Johansson <[email protected]>

---
NOTE: I've not included any reviewed-bys or modified this patch as it's
still unclear to me whether this change is correct or not.  Alistair
mentioned that this can get called for MXLEN == 32 and upper_half ==
false, meaning the lower field would be accessed.  I'm sure I'm missing
something but this is still not clear to me, it seems to me like we
always want to access the upper half for MXLEN == 32 since that's were
the inhibit flags are stored.

In case there is a doubt, having an assert for this situation would make it future proof.
g_assert(!(rv32 && !upper_half));

As well, maybe Alistair can point a call site where this combination is possible.

---
  target/riscv/csr.c | 22 ++++++++++------------
  1 file changed, 10 insertions(+), 12 deletions(-)


Reply via email to