Re: [PATCH v3 10/13] target/hexagon: add COREDUMP semihosting operation
Matheus Tavares Bernardino <[email protected]>
| Newsgroups | gmane.comp.emulators.qemu |
|---|---|
| Message-ID | <[email protected]> |
On Mon, 17 Aug 2026 06:34:54 +0200 =?UTF-8?Q?Philippe_Mathieu-Daud=C3=A9?= <[email protected]> wrote: > > On 20/7/26 19:41, Matheus Tavares Bernardino wrote: > > Baremetal Hexagon programs invoke SYS_COREDUMP (0xCD) > > through semihosting to dump CPU state on a fatal exception. > > Implement the handler to decode the SSR cause field and > > print the full register file, matching hexagon-sim behavior. > > > > Signed-off-by: Brian Cain <[email protected]> > > Reviewed-by: Pierrick Bouvier <[email protected]> > > Signed-off-by: Matheus Tavares Bernardino <[email protected]> > > --- > > target/hexagon/internal.h | 1 + > > target/hexagon/cpu.c | 2 +- > > target/hexagon/hexswi.c | 143 ++++++++++++++++++++++++++++++++++++++ > > 3 files changed, 145 insertions(+), 1 deletion(-) > > > > diff --git a/target/hexagon/cpu.c b/target/hexagon/cpu.c > > index e6b2ac1939d..06c378c5e02 100644 > > --- a/target/hexagon/cpu.c > > +++ b/target/hexagon/cpu.c > > @@ -232,7 +232,7 @@ void hexagon_debug_qreg(CPUHexagonState *env, int regnum) > > print_qreg(stdout, env, regnum, false); > > } > > > > -static void hexagon_dump(CPUHexagonState *env, FILE *f, int flags) > > +void hexagon_dump(CPUHexagonState *env, FILE *f, int flags) > > { > > HexagonCPU *cpu = env_archcpu(env); > > > > diff --git a/target/hexagon/hexswi.c b/target/hexagon/hexswi.c > > index 6efc00fedf9..564a11e557a 100644 > > --- a/target/hexagon/hexswi.c > > +++ b/target/hexagon/hexswi.c > > @@ -162,6 +162,145 @@ static void common_semi_ftell_cb(CPUState *cs, uint64_t ret, int err) > > common_semi_cb(cs, ret, err); > > } > > > > +static void coredump(CPUHexagonState *env) > > +{ > > + uint32_t ssr = arch_get_system_reg(env, HEX_SREG_SSR); > > + FILE *f = qemu_log_trylock(); > > + > > + if (!f) { > > + return; > > + } > > + > > + fprintf(f, "CRASH!\n"); > > + fprintf(f, "I think the exception was: "); > > + switch (GET_SSR_FIELD(SSR_CAUSE, ssr)) { > > + case 0x43: > > + fprintf(f, "0x43, NMI"); > > + break; > > + case 0x42: > > + fprintf(f, "0x42, Data abort"); > > + break; > > + case 0x44: > > + fprintf(f, "0x44, Multi TLB match"); > > + break; > > + case HEX_CAUSE_BIU_PRECISE: > > + fprintf(f, "0x%x, Bus Error (Precise BIU error)", > > + HEX_CAUSE_BIU_PRECISE); > > + break; > [...] > > Should this be moved within hexagon_dump() instead? That information > seems available and useful there. Hmm, we could extract this out of coredump() if there are other users, but I don't think it would be useful at hexagon_dump()... This info is only meaningful right after an exception. In a generic cpu_dump_state() call, SSR could be 0 or even hold the value of the last exception, so "CRASH, I think the exception was..." would be misleading there.