All of lore.kernel.org
 help / color / mirror / Atom feed
From: Richard Henderson <richard.henderson@linaro.org>
To: Song Gao <gaosong@loongson.cn>, qemu-devel@nongnu.org
Cc: Xiaojuan Yang <yangxiaojuan@loongson.cn>, laurent@vivier.eu
Subject: Re: [PATCH v10 16/26] target/loongarch: Add disassembler
Date: Fri, 12 Nov 2021 08:39:42 +0100	[thread overview]
Message-ID: <22148b72-1696-2420-c937-7e0ce083f963@linaro.org> (raw)
In-Reply-To: <1636700049-24381-17-git-send-email-gaosong@loongson.cn>

On 11/12/21 7:53 AM, Song Gao wrote:
> +const char * const fccregnames[8] = {
> +  "$fcc0", "$fcc1", "$fcc2", "$fcc3", "$fcc4", "$fcc5", "$fcc6", "$fcc7",
> +};

static.

> +static void output_fcsrdrj(DisasContext *ctx, arg_fmt_fcsrdrj *a,
> +                           const char *mnemonic)
> +{
> +    output(ctx, mnemonic, "%s, %s", regnames[a->fcsrd], regnames[a->rj]);
> +}
> +
> +static void output_rdfcsrs(DisasContext *ctx, arg_fmt_rdfcsrs *a,
> +                           const char *mnemonic)
> +{
> +    output(ctx, mnemonic, "%s, %s", regnames[a->rd], regnames[a->fcsrs]);
> +}

Wrong names for fcsr[ds].  Probably easiest to just use "fcsr%d" rather than having an 
array of strings.

> +static void output_rdrjsi12(DisasContext *ctx, arg_fmt_rdrjsi12 *a,
> +                            const char *mnemonic)
> +{
> +    output(ctx, mnemonic, "%s, %s, 0x%x",
> +           regnames[a->rd], regnames[a->rj], (a->si12) & 0xfff);
> +}

Surely printing the signed value is more useful.

> +static void output_rdrjsi16(DisasContext *ctx, arg_fmt_rdrjsi16 *a,
> +                            const char *mnemonic)
> +{
> +    output(ctx, mnemonic, "%s, %s, 0x%x",
> +           regnames[a->rd], regnames[a->rj], (a->si16) & 0xffff);
> +}
> +
> +static void output_rdsi20(DisasContext *ctx, arg_fmt_rdsi20 *a,
> +                          const char *mnemonic)
> +{
> +    output(ctx, mnemonic, "%s, 0x%x", regnames[a->rd], (a->si20) & 0xfffff);
> +}
> +
> +static void output_rdrjsi14(DisasContext *ctx, arg_fmt_rdrjsi14 *a,
> +                            const char *mnemonic)
> +{
> +    output(ctx, mnemonic, "%s, %s, 0x%x",
> +           regnames[a->rd], regnames[a->rj],  (a->si14) & 0x3fff);
> +}
> +
> +static void output_hintrjsi12(DisasContext *ctx, arg_fmt_hintrjsi12 *a,
> +                              const char *mnemonic)
> +{
> +    output(ctx, mnemonic, "0x%x, %s, 0x%x",
> +           a->hint, regnames[a->rj], (a->si12) & 0xfff);
> +}
> +
> +static void output_fdrjsi12(DisasContext *ctx, arg_fmt_fdrjsi12 *a,
> +                            const char *mnemonic)
> +{
> +    output(ctx, mnemonic, "%s, %s, 0x%x",
> +           fregnames[a->fd], regnames[a->rj], (a->si12) & 0xfff);
> +}

Likewise.

> +static void output_rjoffs21(DisasContext *ctx, arg_fmt_rjoffs21 *a,
> +                            const char *mnemonic)
> +{
> +    output(ctx, mnemonic, "%s, 0x%x", regnames[a->rj], (a->offs21) & 0x1fffff);
> +}
> +
> +static void output_cjoffs21(DisasContext *ctx, arg_fmt_cjoffs21 *a,
> +                            const char *mnemonic)
> +{
> +    output(ctx, mnemonic, "%s, 0x%x",
> +           fccregnames[a->cj], (a->offs21) & 0x1fffff);
> +}
> +
> +static void output_rdrjoffs16(DisasContext *ctx, arg_fmt_rdrjoffs16 *a,
> +                              const char *mnemonic)
> +{
> +    output(ctx, mnemonic, "%s, %s, 0x%x",
> +           regnames[a->rd], regnames[a->rj], (a->offs16) & 0xffff);
> +}
> +
> +static void output_offs(DisasContext *ctx, arg_fmt_offs *a,
> +                        const char *mnemonic)
> +{
> +    output(ctx, mnemonic, "0x%x", (a->offs) & 0x3ffffff);
> +}

These are signed, but they're also pc-relative.  It's probably most helpful to have stored 
the address into ctx and compute the final address.

> +static void output_rdfj(DisasContext *ctx, arg_fmt_rdfj *a,
> +                        const char *mnemonic)
> +{
> +    output(ctx, mnemonic, "%s, %s", regnames[a->rd], regnames[a->fj]);
> +}

Wrong name for fj.

> +#define output_fcmp(C, PREFIX, SUBFFIX)                                     \

SUFFIX

> +static void output_cdfjfkfcond(DisasContext *ctx, arg_fmt_cdfjfkfcond * a,
> +                               const char *suffix)
> +{
> +    switch (a->fcond) {
> +    case 0x0:
> +        output_fcmp(ctx, "fcmp_caf_", suffix);
> +        break;
> +    case 0x1:
> +        output_fcmp(ctx, "fcmp_saf_", suffix);
> +        break;
> +    case 0x2:
> +        output_fcmp(ctx, "fcmp_clt_", suffix);
> +        break;
> +    case 0x3:
> +        output_fcmp(ctx, "fcmp_slt_", suffix);
> +        break;
> +    case 0x4:
> +        output_fcmp(ctx, "fcmp_ceq_", suffix);
> +        break;
> +    case 0x5:
> +        output_fcmp(ctx, "fcmp_seq_", suffix);
> +        break;
> +    case 0x6:
> +        output_fcmp(ctx, "fcmp_cle_", suffix);
> +        break;
> +    case 0x7:
> +        output_fcmp(ctx, "fcmp_sle_", suffix);
> +        break;
> +    case 0x8:
> +        output_fcmp(ctx, "fcmp_cun_", suffix);
> +        break;
> +    case 0x9:
> +        output_fcmp(ctx, "fcmp_sun_", suffix);
> +        break;
> +    case 0xA:
> +        output_fcmp(ctx, "fcmp_cult_", suffix);
> +        break;
> +    case 0xB:
> +        output_fcmp(ctx, "fcmp_sult_", suffix);
> +        break;
> +    case 0xC:
> +        output_fcmp(ctx, "fcmp_cueq_", suffix);
> +        break;
> +    case 0xD:
> +        output_fcmp(ctx, "fcmp_sueq_", suffix);
> +        break;
> +    case 0xE:
> +        output_fcmp(ctx, "fcmp_cule_", suffix);
> +        break;
> +    case 0xF:
> +        output_fcmp(ctx, "fcmp_sule_", suffix);
> +        break;
> +    case 0x10:
> +        output_fcmp(ctx, "fcmp_cne_", suffix);
> +        break;
> +    case 0x11:
> +        output_fcmp(ctx, "fcmp_sne_", suffix);
> +        break;
> +    case 0x14:
> +        output_fcmp(ctx, "fcmp_cor_", suffix);
> +        break;
> +    case 0x15:
> +        output_fcmp(ctx, "fcmp_sor_", suffix);
> +        break;
> +    case 0x18:
> +        output_fcmp(ctx, "fcmp_cune_", suffix);
> +        break;
> +    case 0x19:
> +        output_fcmp(ctx, "fcmp_sune_", suffix);
> +        break;
> +    default:
> +        break;

Here you're going to print nothing at all, which is wrong.

> +    }
> +}
> +
> +#define FCMP_INSN(insn, suffix, type)                           \
> +static bool trans_##insn(DisasContext *ctx, arg_fmt_##type * a) \
> +{                                                               \
> +    output_##type(ctx, a, #suffix);                             \
> +    return true;                                                \
> +}

I think you should drop "insn" and "type" from this define and use output_cdfjfkfcond 
directly.

I think that FCMP_INSN should return output_cdfjfkfcond, which should return false for the 
default case, so that decodetree returns false, so that we print "invalid".


r~


  reply	other threads:[~2021-11-12  7:42 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-12  6:53 [PATCH v10 00/26] Add LoongArch linux-user emulation support Song Gao
2021-11-12  6:53 ` [PATCH v10 01/26] target/loongarch: Add README Song Gao
2021-11-12  6:53 ` [PATCH v10 02/26] target/loongarch: Add core definition Song Gao
2021-11-12  6:53 ` [PATCH v10 03/26] target/loongarch: Add main translation routines Song Gao
2021-11-12  6:53 ` [PATCH v10 04/26] target/loongarch: Add fixed point arithmetic instruction translation Song Gao
2021-11-12 14:05   ` Richard Henderson
2021-11-13  3:18     ` WANG Xuerui
2021-11-15  3:59     ` gaosong
2021-11-15  8:42       ` Richard Henderson
2021-11-17  7:57         ` gaosong
2021-11-17  8:28           ` Richard Henderson
2021-11-17  9:29             ` gaosong
2021-11-17  9:55               ` Richard Henderson
2021-11-18  1:24                 ` gaosong
2021-11-12  6:53 ` [PATCH v10 05/26] target/loongarch: Add fixed point shift " Song Gao
2021-11-12  6:53 ` [PATCH v10 06/26] target/loongarch: Add fixed point bit " Song Gao
2021-11-12  6:53 ` [PATCH v10 07/26] target/loongarch: Add fixed point load/store " Song Gao
2021-11-12  6:53 ` [PATCH v10 08/26] target/loongarch: Add fixed point atomic " Song Gao
2021-11-12  6:53 ` [PATCH v10 09/26] target/loongarch: Add fixed point extra " Song Gao
2021-11-12  6:53 ` [PATCH v10 10/26] target/loongarch: Add floating point arithmetic " Song Gao
2021-11-12  6:53 ` [PATCH v10 11/26] target/loongarch: Add floating point comparison " Song Gao
2021-11-12  6:53 ` [PATCH v10 12/26] target/loongarch: Add floating point conversion " Song Gao
2021-11-12  6:53 ` [PATCH v10 13/26] target/loongarch: Add floating point move " Song Gao
2021-11-12  6:53 ` [PATCH v10 14/26] target/loongarch: Add floating point load/store " Song Gao
2021-11-12  6:53 ` [PATCH v10 15/26] target/loongarch: Add branch " Song Gao
2021-11-12  6:53 ` [PATCH v10 16/26] target/loongarch: Add disassembler Song Gao
2021-11-12  7:39   ` Richard Henderson [this message]
2021-11-12  9:59     ` gaosong
2021-11-12  6:54 ` [PATCH v10 17/26] linux-user: Add LoongArch generic header files Song Gao
2021-11-16  8:33   ` Philippe Mathieu-Daudé
2021-11-16 11:50     ` gaosong
2021-11-12  6:54 ` [PATCH v10 18/26] linux-user: Add LoongArch specific structures Song Gao
2021-11-12  6:54 ` [PATCH v10 19/26] linux-user: Add LoongArch signal support Song Gao
2021-11-12  6:54 ` [PATCH v10 20/26] linux-user: Add LoongArch elf support Song Gao
2021-11-12  6:54 ` [PATCH v10 21/26] linux-user: Add LoongArch syscall support Song Gao
2021-11-12  6:54 ` [PATCH v10 22/26] linux-user: Add LoongArch cpu_loop support Song Gao
2021-11-12  6:54 ` [PATCH v10 23/26] default-configs: Add loongarch linux-user support Song Gao
2021-11-12  6:54 ` [PATCH v10 24/26] target/loongarch: Add target build suport Song Gao
2021-11-12  6:54 ` [PATCH v10 25/26] target/loongarch: 'make check-tcg' support Song Gao
2021-11-12  6:54 ` [PATCH v10 26/26] scripts: add loongarch64 binfmt config Song Gao

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=22148b72-1696-2420-c937-7e0ce083f963@linaro.org \
    --to=richard.henderson@linaro.org \
    --cc=gaosong@loongson.cn \
    --cc=laurent@vivier.eu \
    --cc=qemu-devel@nongnu.org \
    --cc=yangxiaojuan@loongson.cn \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.