Hexagon: improve output for arch version debugging
cover Hexagon: improve output for arch version debugging
If we run qemu with an Hexagon binary compiled to an arch version that is higher than the threshold modeled by qemu, we will get the following error:
qemu-hexagon: unable to find CPU model 'unknown'
This can be confusing ("Was qemu unable to read the arch version from this binary? Or did it read but does not know such version?").
And running qemu-hexagon -cpu help doesn't help either, as it just errors out with no output. This patchset tries to improve this process.
https://lore.kernel.org/qemu-devel/[email protected]/
Matheus Tavares Bernardino (2):
Hexagon: list available CPUs with -cpu help
Hexagon: append eflags to unknown cpu model string
linux-user/hexagon/target_elf.h | 7 ++++++- target/hexagon/cpu.h | 3 +++ target/hexagon/cpu.c | 20 ++++++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-)
Signature · 1 line
2.37.2
PATCH 1/2 Hexagon: list available CPUs with `-cpu help`
Currently, qemu-hexagon only models the v67 cpu. Nonetheless if we try to get this information with -cpu help, qemu just exists with an error code and no output. Let's correct that.
The code is basically a copy from target/alpha/cpu.h, but we strip the "-hexagon-cpu" suffix before printing. This is to avoid confusing situations like the following:
$ qemu-hexagon -cpu help
Available CPUs:
v67-hexagon-cpu
$ qemu-hexagon -cpu v67-hexagon-cpu ./prog
qemu-hexagon: unable to find CPU model 'v67-hexagon-cpu'
--- target/hexagon/cpu.h | 3 +++ target/hexagon/cpu.c | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+)
target/hexagon/cpu.h +3 -0
@@ -44,6 +44,9 @@#define TYPE_HEXAGON_CPU_V67 HEXAGON_CPU_TYPE_NAME("v67") +void hexagon_cpu_list (void ); +#define cpu_list hexagon_cpu_list +#define MMU_USER_IDX 0 typedef struct {
target/hexagon/cpu.c +20 -0
@@ -29,6 +29,26 @@ static void hexagon_v67_cpu_init(Object *obj) { } +static void hexagon_cpu_list_entry (gpointer data,gpointer user_data) +{ +ObjectClass *oc = data; +char *name =g_strdup (object_class_get_name (oc)); +if (g_str_has_suffix (name,HEXAGON_CPU_TYPE_SUFFIX )) { + name[strlen (name) -strlen (HEXAGON_CPU_TYPE_SUFFIX )] ='\0' ; + } +qemu_printf (" %s\n" , name); +g_free (name); +} + +void hexagon_cpu_list (void ) +{ +GSList *list; + list =object_class_get_list_sorted (TYPE_HEXAGON_CPU , false); +qemu_printf ("Available CPUs:\n" ); +g_slist_foreach (list, hexagon_cpu_list_entry,NULL ); +g_slist_free (list); +} +static ObjectClass *hexagon_cpu_class_by_name (const char *cpu_model) {ObjectClass *oc;
Signature · 1 line
2.37.2
PATCH 2/2 Hexagon: append eflags to unknown cpu model string
In reply to Matheus Tavares BernardinoRunning qemu-hexagon with a binary that was compiled for an arch version unknown by qemu can produce a somewhat confusing message:
qemu-hexagon: unable to find CPU model 'unknown'
Let's give a bit more info by appending the eflags so that the message becomes:
qemu-hexagon: unable to find CPU model 'unknown (0x69)'
--- linux-user/hexagon/target_elf.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
linux-user/hexagon/target_elf.h +6 -1
@@ -20,6 +20,9 @@static inline const char *cpu_get_model (uint32_t eflags) { +static char buf[32 ]; +int err; +/* For now, treat anything newer than v5 as a v67 */ /* FIXME - Disable instructions that are newer than the specified arch */ if (eflags == 0x04 || /* v5 */
@@ -34,7 +37,9 @@ static inline const char *cpu_get_model(uint32_t eflags) ) {return "v67" ; } - return "unknown"; + + err =snprintf (buf,sizeof (buf),"unknown (0x%x)" , eflags); + return err >= 0 && err < sizeof(buf) ? buf : "unknown"; }#endif
Signature · 1 line
2.37.2
RE: [PATCH 1/2] Hexagon: list available CPUs with `-cpu help`
In reply to Matheus Tavares BernardinoQuoted 25 lines
-----Original Message-----
From: Matheus Tavares Bernardino <[email protected]>
Sent: Thursday, May 4, 2023 1:53 PM
To: [email protected]
Cc: Brian Cain <[email protected]>; Taylor Simpson <[email protected]>
Subject: [PATCH 1/2] Hexagon: list available CPUs with-cpu helpCurrently, qemu-hexagon only models the v67 cpu. Nonetheless if we try to get this information with
-cpu help, qemu just exists with an error code and no output. Let's correct that.The code is basically a copy from
target/alpha/cpu.h, but we strip the "- hexagon-cpu" suffix before printing. This is to avoid confusing situations like the following:$ qemu-hexagon -cpu helpAvailable CPUs:
v67-hexagon-cpu$ qemu-hexagon -cpu v67-hexagon-cpu ./prog
Quoted 7 lines
qemu-hexagon: unable to find CPU model 'v67-hexagon-cpu'
Signed-off-by Matheus Tavares Bernardino <[email protected]>--- target/hexagon/cpu.h | 3 +++ target/hexagon/cpu.c | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+)
RE: [PATCH 2/2] Hexagon: append eflags to unknown cpu model string
In reply to Matheus Tavares BernardinoQuoted 18 lines
-----Original Message-----
From: Matheus Tavares Bernardino <[email protected]>
Sent: Thursday, May 4, 2023 1:53 PM
To: [email protected]
Cc: Brian Cain <[email protected]>; Taylor Simpson <[email protected]>; Laurent Vivier <[email protected]>
Subject: [PATCH 2/2] Hexagon: append eflags to unknown cpu model stringRunning qemu-hexagon with a binary that was compiled for an arch version unknown by qemu can produce a somewhat confusing message:
qemu-hexagon: unable to find CPU model 'unknown'
Let's give a bit more info by appending the eflags so that the message becomes:
Quoted 6 lines
qemu-hexagon: unable to find CPU model 'unknown (
0x69)'Signed-off-by Matheus Tavares Bernardino <[email protected]>--- linux-user/hexagon/target_elf.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
Quoted 25 lines
-----Original Message-----
From: Matheus Tavares Bernardino <[email protected]>
Sent: Thursday, May 4, 2023 1:53 PM
To: [email protected]
Cc: Brian Cain <[email protected]>; Taylor Simpson <[email protected]>
Subject: [PATCH 0/2] Hexagon: improve output for arch version debuggingIf we run qemu with an Hexagon binary compiled to an arch version that is higher than the threshold modeled by qemu, we will get the following error:
qemu-hexagon: unable to find CPU model 'unknown'
This can be confusing ("Was qemu unable to read the arch version from this binary? Or did it read but does not know such version?").
And running
qemu-hexagon -cpu helpdoesn't help either, as it just errors out with no output. This patchset tries to improve this process.
Quoted 8 lines
Matheus Tavares Bernardino (2):
Hexagon: list available CPUs with-cpu help
Hexagon: append eflags to unknown cpu model stringlinux-user/hexagon/target_elf.h | 7 ++++++- target/hexagon/cpu.h | 3 +++ target/hexagon/cpu.c | 20 ++++++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-)
Queued for next Hexagon PR
Thanks,
Taylor