riscv-software-src / opensbi

RISC-V Open Source Supervisor Binary Interface
Other
1.03k stars 511 forks source link

`sbi_cppc_write` is never passed the full 64-bit value when `__riscv_xlen == 32` #334

Closed repnop closed 1 month ago

repnop commented 11 months ago

https://github.com/riscv-software-src/opensbi/blob/791704cd09c019decf438f6e4f56423cc95cb66a/lib/sbi/sbi_ecall_cppc.c#L36

Unless there's something I've missed in the SBI specification about CPPC register values never exceeding 32-bits when XLEN is 32, this line is wrong whenever the code is compiled for __riscv_xlen == 32, as it implicitly promotes the unsigned long (32-bits) to a uint64_t instead of reading the full 64-bit value out of a1 and a2 and combining them into a 64-bit value.

avpatel commented 11 months ago

Yes, this line needs to be fixed for RV32. Please send a patch to the OpenSBI mailing list.