Re: [PATCH 08/12] target/riscv: seed cfg.big_endian from TargetInfo
Philippe Mathieu-Daudé <[email protected]>
| Newsgroups | org.nongnu.qemu-riscv,org.nongnu.qemu-arm,org.nongnu.qemu-devel |
|---|---|
| Message-ID | <[email protected]> |
On 23/8/26 17:07, Yonggang Luo wrote: > GDB register packets use target_big_endian() only (gdb_get_reg16/32/64). > RISC-V gdbstub already goes through those helpers, so future GDB > big-endian support does not need a second endian source in the CPU > gdbstub. It needs TargetInfo and the hart to agree. > > Hart endian is cpu->cfg.big_endian, copied into mstatus MBE/SBE/UBE at > reset. The CPU property still defaults to little-endian, so a > big-endian TargetInfo would make GDB swap as BE while the hart stayed > LE. > > - Initialize cfg.big_endian from target_big_endian() in cpu init so a > big-endian TargetInfo also sets the hart. > - Fail realize when -cpu big-endian= disagrees with that selection. > GDB cannot follow a per-CPU override, so a split would silently > corrupt register byte order. > > Signed-off-by: Yonggang Luo <[email protected]> > --- > target/riscv/cpu.c | 10 ++++++++++ > 1 file changed, 10 insertions(+) > > diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c > index 5a82e6563bf..0681bec0bef 100644 > --- a/target/riscv/cpu.c > +++ b/target/riscv/cpu.c > @@ -29,6 +29,7 @@ > #include "qapi/error.h" > #include "qapi/visitor.h" > #include "qemu/error-report.h" > +#include "qemu/target-info.h" > #include "qemu/timer.h" > #include "hw/core/qdev-properties.h" > #include "hw/core/qdev-prop-internal.h" > @@ -1226,6 +1227,13 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp) > RISCVCPUClass *mcc = RISCV_CPU_GET_CLASS(dev); > Error *local_err = NULL; > > + if (cpu->cfg.big_endian != target_big_endian()) { > + error_setg(errp, > + "CPU big-endian=%s does not match selected target endian", > + cpu->cfg.big_endian ? "on" : "off"); Surely the bug is on the GDB path. > + return; > + } > + > cpu_exec_realizefn(cs, &local_err); > if (local_err != NULL) { > error_propagate(errp, local_err);