qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Eduardo Habkost <ehabkost@redhat.com>
To: "Philippe Mathieu-Daudé" <f4bug@amsat.org>
Cc: "Igor Mammedov" <imammedo@redhat.com>,
	"Hervé Poussineau" <hpoussin@reactos.org>,
	"Aurelien Jarno" <aurelien@aurel32.net>,
	"Marcel Apfelbaum" <marcel@redhat.com>,
	"James Hogan" <james.hogan@imgtec.com>,
	"Yongbok Kim" <yongbok.kim@imgtec.com>,
	"Thomas Huth" <thuth@redhat.com>,
	qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH v2 7/7] mips: update mips_cpu_list() to use object_class_get_list()
Date: Fri, 15 Sep 2017 21:20:13 -0300	[thread overview]
Message-ID: <20170916002013.GD21016@localhost.localdomain> (raw)
In-Reply-To: <20170830225225.27925-8-f4bug@amsat.org>

On Wed, Aug 30, 2017 at 07:52:25PM -0300, Philippe Mathieu-Daudé wrote:
> while here, move it from translate_init.c to helper.c
> 
> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> Tested-by: Igor Mammedov <imammedo@redhat.com>
> Tested-by: James Hogan <james.hogan@imgtec.com>
> ---
>  target/mips/helper.c         | 46 ++++++++++++++++++++++++++++++++++++++++++++
>  target/mips/translate_init.c | 10 ----------
>  2 files changed, 46 insertions(+), 10 deletions(-)
> 
> diff --git a/target/mips/helper.c b/target/mips/helper.c
> index ea076261af..8d12b0088a 100644
> --- a/target/mips/helper.c
> +++ b/target/mips/helper.c
> @@ -1093,3 +1093,49 @@ void QEMU_NORETURN do_raise_exception_err(CPUMIPSState *env,
>  
>      cpu_loop_exit_restore(cs, pc);
>  }
> +
> +/* Sort alphabetically by type name, except for "any". */
> +static gint mips_cpu_list_compare(gconstpointer a, gconstpointer b)
> +{
> +    ObjectClass *class_a = (ObjectClass *)a;
> +    ObjectClass *class_b = (ObjectClass *)b;
> +    const char *name_a, *name_b;
> +
> +    name_a = object_class_get_name(class_a);
> +    name_b = object_class_get_name(class_b);
> +    if (strcmp(name_a, "any-" TYPE_MIPS_CPU) == 0) {
> +        return 1;
> +    } else if (strcmp(name_b, "any-" TYPE_MIPS_CPU) == 0) {
> +        return -1;
> +    } else {
> +        return strcmp(name_a, name_b);
> +    }

This works, but I'd prefer to do like x86 and have a
MIPSCPUClass::ordering field.

(Or, even better: to add a generic CPUClass::ordering field so
all architectures can use the same method to order the model
list)

> +}
> +
> +static void mips_cpu_list_entry(gpointer data, gpointer user_data)
> +{
> +    ObjectClass *oc = data;
> +    CPUListState *s = user_data;
> +    const char *typename;
> +    char *name;
> +
> +    typename = object_class_get_name(oc);
> +    name = g_strndup(typename, strlen(typename) - strlen("-" TYPE_MIPS_CPU));
> +    (*s->cpu_fprintf)(s->file, "  %s\n", name);
> +    g_free(name);
> +}
> +
> +void mips_cpu_list(FILE *f, fprintf_function cpu_fprintf)
> +{
> +    CPUListState s = {
> +        .file = f,
> +        .cpu_fprintf = cpu_fprintf,
> +    };
> +    GSList *list;
> +
> +    list = object_class_get_list(TYPE_MIPS_CPU, false);
> +    list = g_slist_sort(list, mips_cpu_list_compare);
> +    (*cpu_fprintf)(f, "Available CPUs:\n");
> +    g_slist_foreach(list, mips_cpu_list_entry, &s);
> +    g_slist_free(list);
> +}

I think it's about time we implement a generic mechanism to list
CPU models using the QOM hierarchy, but this is out of the scope
of this series.


> diff --git a/target/mips/translate_init.c b/target/mips/translate_init.c
> index 8bbded46c4..b75f4c9065 100644
> --- a/target/mips/translate_init.c
> +++ b/target/mips/translate_init.c
> @@ -767,16 +767,6 @@ static const mips_def_t *cpu_mips_find_by_name (const char *name)
>      return NULL;
>  }
>  
> -void mips_cpu_list (FILE *f, fprintf_function cpu_fprintf)
> -{
> -    int i;
> -
> -    for (i = 0; i < ARRAY_SIZE(mips_defs); i++) {
> -        (*cpu_fprintf)(f, "MIPS '%s'\n",
> -                       mips_defs[i].name);
> -    }
> -}
> -
>  #ifndef CONFIG_USER_ONLY
>  static void no_mmu_init (CPUMIPSState *env, const mips_def_t *def)
>  {
> -- 
> 2.14.1
> 
> 

-- 
Eduardo

  reply	other threads:[~2017-09-16  0:20 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-30 22:52 [Qemu-devel] [PATCH v2 0/7] QOMify MIPS cpu Philippe Mathieu-Daudé
2017-08-30 22:52 ` [Qemu-devel] [PATCH v2 1/7] mips: move hw/mips/cputimer.c to target/mips/ Philippe Mathieu-Daudé
2017-08-30 22:52 ` [Qemu-devel] [PATCH v2 2/7] mips: introduce internal.h and cleanup cpu.h Philippe Mathieu-Daudé
2017-08-30 22:52 ` [Qemu-devel] [PATCH v2 3/7] mips: split cpu_mips_realize_env() out of cpu_mips_init() Philippe Mathieu-Daudé
2017-09-14 19:48   ` Eduardo Habkost
2017-08-30 22:52 ` [Qemu-devel] [PATCH v2 4/7] mips: call cpu_mips_realize_env() from mips_cpu_realizefn() Philippe Mathieu-Daudé
2017-09-15 23:50   ` Eduardo Habkost
2017-08-30 22:52 ` [Qemu-devel] [PATCH v2 5/7] mips: MIPSCPU model subclasses Philippe Mathieu-Daudé
2017-09-16  0:15   ` Eduardo Habkost
2017-09-17 22:38     ` Philippe Mathieu-Daudé
2017-08-30 22:52 ` [Qemu-devel] [PATCH v2 6/7] mips: replace cpu_mips_init() with cpu_generic_init() Philippe Mathieu-Daudé
2017-09-16  0:16   ` Eduardo Habkost
2017-08-30 22:52 ` [Qemu-devel] [PATCH v2 7/7] mips: update mips_cpu_list() to use object_class_get_list() Philippe Mathieu-Daudé
2017-09-16  0:20   ` Eduardo Habkost [this message]
2017-09-17 22:40     ` Philippe Mathieu-Daudé
2017-08-30 23:01 ` [Qemu-devel] [PATCH v2 0/7] QOMify MIPS cpu no-reply
2017-08-31  3:57 ` Philippe Mathieu-Daudé
2017-09-01 15:18 ` Eduardo Habkost
2017-09-01 15:44   ` Philippe Mathieu-Daudé
2017-09-01 15:48     ` Eduardo Habkost
2017-09-01 16:09       ` Philippe Mathieu-Daudé
2017-09-04 13:32         ` Yongbok Kim
2017-09-10 17:43           ` Philippe Mathieu-Daudé

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170916002013.GD21016@localhost.localdomain \
    --to=ehabkost@redhat.com \
    --cc=aurelien@aurel32.net \
    --cc=f4bug@amsat.org \
    --cc=hpoussin@reactos.org \
    --cc=imammedo@redhat.com \
    --cc=james.hogan@imgtec.com \
    --cc=marcel@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=thuth@redhat.com \
    --cc=yongbok.kim@imgtec.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).