diff mbox series

[1/2] Hexagon: list available CPUs with `-cpu help`

Message ID b946e17c7e17eed9095700b54c5ead36e5d55dfa.1683225804.git.quic_mathbern@quicinc.com
State New
Headers show
Series Hexagon: improve output for arch version debugging | expand

Commit Message

Matheus Tavares Bernardino May 4, 2023, 6:53 p.m. UTC
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'

Signed-off-by: Matheus Tavares Bernardino <quic_mathbern@quicinc.com>
---
 target/hexagon/cpu.h |  3 +++
 target/hexagon/cpu.c | 20 ++++++++++++++++++++
 2 files changed, 23 insertions(+)

Comments

Taylor Simpson May 5, 2023, 6:58 p.m. UTC | #1
> -----Original Message-----
> From: Matheus Tavares Bernardino <quic_mathbern@quicinc.com>
> Sent: Thursday, May 4, 2023 1:53 PM
> To: qemu-devel@nongnu.org
> Cc: Brian Cain <bcain@quicinc.com>; Taylor Simpson
> <tsimpson@quicinc.com>
> Subject: [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'
> 
> Signed-off-by: Matheus Tavares Bernardino <quic_mathbern@quicinc.com>
> ---
>  target/hexagon/cpu.h |  3 +++
>  target/hexagon/cpu.c | 20 ++++++++++++++++++++
>  2 files changed, 23 insertions(+)

Reviewed-by: Taylor Simpson <tsimpson@quicinc.com>
Tested-by: Taylor Simpson <tsimpson@quicinc.com>
diff mbox series

Patch

diff --git a/target/hexagon/cpu.h b/target/hexagon/cpu.h
index 81b663ecfb..d59e5bbff8 100644
--- a/target/hexagon/cpu.h
+++ b/target/hexagon/cpu.h
@@ -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 {
diff --git a/target/hexagon/cpu.c b/target/hexagon/cpu.c
index ab40cfc283..e8c2b5e910 100644
--- a/target/hexagon/cpu.c
+++ b/target/hexagon/cpu.c
@@ -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;