From: Marcus Nilsson <brainbomb@gmail.com>
To: binutils@sourceware.org
Subject: Re: [PATCH] opcodes/avr: Implement style support in the disassembler
Date: Fri, 17 Jun 2022 10:57:12 +0200 [thread overview]
Message-ID: <CAA1E49usMK+-_mrcGPVLGrDuR-Tc0ELgvn63QjVV151-KMSP+A@mail.gmail.com> (raw)
In-Reply-To: <20220606191118.550423-1-brainbomb@gmail.com>
Light ping on this one, any comments?
Thanks,
Marcus Nilsson
On Mon, Jun 6, 2022 at 9:11 PM Marcus Nilsson <brainbomb@gmail.com> wrote:
> Update the AVR disassembler to supply style information to the
> disassembler output.
>
> By adding an additional parameter to avr_operand() we can fill in
> style information for each operand. The output formatting remains
> unchanged.
>
> opcodes/ChangeLog:
> * disassemble.c: (disassemble_init_for_target): Set
> created_styled_output for AVR based targets.
> * avr-dis.c: (print_insn_avr): Use fprintf_styled_ftype
> instead of fprintf_ftype throughout.
> (avr_operand): Pass in and fill disassembler_style when
> parsing operands.
> ---
> opcodes/avr-dis.c | 51 +++++++++++++++++++++++++++++++++++--------
> opcodes/disassemble.c | 5 +++++
> 2 files changed, 47 insertions(+), 9 deletions(-)
>
> diff --git a/opcodes/avr-dis.c b/opcodes/avr-dis.c
> index aab37962688..0614e7dd746 100644
> --- a/opcodes/avr-dis.c
> +++ b/opcodes/avr-dis.c
> @@ -56,6 +56,7 @@ avr_operand (unsigned int insn,
> char * opcode_str,
> char * buf,
> char * comment,
> + enum disassembler_style * style,
> int regs,
> int * sym,
> bfd_vma * sym_addr,
> @@ -74,6 +75,7 @@ avr_operand (unsigned int insn,
> insn = (insn & 0x01f0) >> 4; /* Destination register. */
>
> sprintf (buf, "r%d", insn);
> + *style = dis_style_register;
> break;
>
> case 'd':
> @@ -81,10 +83,13 @@ avr_operand (unsigned int insn,
> sprintf (buf, "r%d", 16 + (insn & 0xf));
> else
> sprintf (buf, "r%d", 16 + ((insn & 0xf0) >> 4));
> +
> + *style = dis_style_register;
> break;
>
> case 'w':
> sprintf (buf, "r%d", 24 + ((insn & 0x30) >> 3));
> + *style = dis_style_register;
> break;
>
> case 'a':
> @@ -92,6 +97,8 @@ avr_operand (unsigned int insn,
> sprintf (buf, "r%d", 16 + (insn & 7));
> else
> sprintf (buf, "r%d", 16 + ((insn >> 4) & 7));
> +
> + *style = dis_style_register;
> break;
>
> case 'v':
> @@ -99,6 +106,8 @@ avr_operand (unsigned int insn,
> sprintf (buf, "r%d", (insn & 0xf) * 2);
> else
> sprintf (buf, "r%d", ((insn & 0xf0) >> 3));
> +
> + *style = dis_style_register;
> break;
>
> case 'e':
> @@ -119,6 +128,7 @@ avr_operand (unsigned int insn,
> default: xyz = "??"; ok = 0;
> }
> strcpy (buf, xyz);
> + *style = dis_style_register;
>
> if (AVR_UNDEF_P (insn))
> sprintf (comment, _("undefined"));
> @@ -143,6 +153,8 @@ avr_operand (unsigned int insn,
> *buf = '\0';
> if (AVR_UNDEF_P (insn))
> sprintf (comment, _("undefined"));
> +
> + *style = dis_style_register;
> break;
>
> case 'b':
> @@ -159,6 +171,7 @@ avr_operand (unsigned int insn,
> *buf++ = 'Z';
> sprintf (buf, "+%d", x);
> sprintf (comment, "0x%02x", x);
> + *style = dis_style_register;
> }
> break;
>
> @@ -173,6 +186,7 @@ avr_operand (unsigned int insn,
> info->insn_info_valid = 1;
> info->insn_type = dis_jsr;
> info->target = *sym_addr;
> + *style = dis_style_address;
> break;
>
> case 'L':
> @@ -185,6 +199,7 @@ avr_operand (unsigned int insn,
> info->insn_info_valid = 1;
> info->insn_type = dis_branch;
> info->target = *sym_addr;
> + *style = dis_style_address_offset;
> }
> break;
>
> @@ -199,6 +214,7 @@ avr_operand (unsigned int insn,
> info->insn_info_valid = 1;
> info->insn_type = dis_condbranch;
> info->target = *sym_addr;
> + *style = dis_style_address_offset;
> }
> break;
>
> @@ -209,6 +225,7 @@ avr_operand (unsigned int insn,
> *sym_addr = val;
> sprintf (buf, "0x%04X", insn2);
> strcpy (comment, comment_start);
> + *style = dis_style_immediate;
> }
> break;
>
> @@ -222,12 +239,14 @@ avr_operand (unsigned int insn,
> *sym_addr = val | 0x800000;
> sprintf (buf, "0x%02x", val);
> strcpy (comment, comment_start);
> + *style = dis_style_immediate;
> }
> break;
>
> case 'M':
> sprintf (buf, "0x%02X", ((insn & 0xf00) >> 4) | (insn & 0xf));
> sprintf (comment, "%d", ((insn & 0xf00) >> 4) | (insn & 0xf));
> + *style = dis_style_immediate;
> break;
>
> case 'n':
> @@ -244,15 +263,18 @@ avr_operand (unsigned int insn,
> x = (insn & 0xf) | ((insn >> 2) & 0x30);
> sprintf (buf, "0x%02x", x);
> sprintf (comment, "%d", x);
> + *style = dis_style_immediate;
> }
> break;
>
> case 's':
> sprintf (buf, "%d", insn & 7);
> + *style = dis_style_immediate;
> break;
>
> case 'S':
> sprintf (buf, "%d", (insn >> 4) & 7);
> + *style = dis_style_immediate;
> break;
>
> case 'P':
> @@ -263,6 +285,7 @@ avr_operand (unsigned int insn,
> x |= (insn >> 5) & 0x30;
> sprintf (buf, "0x%02x", x);
> sprintf (comment, "%d", x);
> + *style = dis_style_address;
> }
> break;
>
> @@ -273,11 +296,13 @@ avr_operand (unsigned int insn,
> x = (insn >> 3) & 0x1f;
> sprintf (buf, "0x%02x", x);
> sprintf (comment, "%d", x);
> + *style = dis_style_address;
> }
> break;
>
> case 'E':
> sprintf (buf, "%d", (insn >> 4) & 15);
> + *style = dis_style_immediate;
> break;
>
> case '?':
> @@ -323,12 +348,13 @@ print_insn_avr (bfd_vma addr, disassemble_info *info)
> const struct avr_opcodes_s *opcode;
> static unsigned int *maskptr;
> void *stream = info->stream;
> - fprintf_ftype prin = info->fprintf_func;
> + fprintf_styled_ftype prin = info->fprintf_styled_func;
> static unsigned int *avr_bin_masks;
> static int initialized;
> int cmd_len = 2;
> int ok = 0;
> char op1[20], op2[20], comment1[40], comment2[40];
> + enum disassembler_style style_op1, style_op2;
> int sym_op1 = 0, sym_op2 = 0;
> bfd_vma sym_addr1, sym_addr2;
>
> @@ -400,6 +426,8 @@ print_insn_avr (bfd_vma addr, disassemble_info *info)
> op2[0] = 0;
> comment1[0] = 0;
> comment2[0] = 0;
> + style_op1 = dis_style_text;
> + style_op2 = dis_style_text;
>
> if (opcode->name)
> {
> @@ -421,12 +449,13 @@ print_insn_avr (bfd_vma addr, disassemble_info *info)
> int regs = REGISTER_P (*constraints);
>
> ok = avr_operand (insn, insn2, addr, *constraints, opcode_str,
> op1,
> - comment1, 0, &sym_op1, &sym_addr1, info);
> + comment1, &style_op1, 0, &sym_op1, &sym_addr1,
> + info);
>
> if (ok && *(++constraints) == ',')
> ok = avr_operand (insn, insn2, addr, *(++constraints),
> opcode_str,
> - op2, *comment1 ? comment2 : comment1, regs,
> - &sym_op2, &sym_addr2, info);
> + op2, *comment1 ? comment2 : comment1,
> + &style_op2, regs, &sym_op2, &sym_addr2,
> info);
> }
> }
>
> @@ -439,22 +468,26 @@ print_insn_avr (bfd_vma addr, disassemble_info *info)
> comment2[0] = 0;
> }
>
> - (*prin) (stream, "%s", ok ? opcode->name : ".word");
> + (*prin) (stream, ok ? dis_style_mnemonic :
> dis_style_assembler_directive,
> + "%s", ok ? opcode->name : ".word");
>
> if (*op1)
> - (*prin) (stream, "\t%s", op1);
> + (*prin) (stream, style_op1, "\t%s", op1);
>
> if (*op2)
> - (*prin) (stream, ", %s", op2);
> + {
> + (*prin) (stream, dis_style_text, ", ");
> + (*prin) (stream, style_op2, "%s", op2);
> + }
>
> if (*comment1)
> - (*prin) (stream, "\t; %s", comment1);
> + (*prin) (stream, dis_style_comment_start, "\t; %s", comment1);
>
> if (sym_op1)
> info->print_address_func (sym_addr1, info);
>
> if (*comment2)
> - (*prin) (stream, " %s", comment2);
> + (*prin) (stream, dis_style_comment_start, " %s", comment2);
>
> if (sym_op2)
> info->print_address_func (sym_addr2, info);
> diff --git a/opcodes/disassemble.c b/opcodes/disassemble.c
> index 5a472ce5349..375ab133439 100644
> --- a/opcodes/disassemble.c
> +++ b/opcodes/disassemble.c
> @@ -624,6 +624,11 @@ disassemble_init_for_target (struct disassemble_info
> * info)
> info->disassembler_needs_relocs = true;
> break;
> #endif
> +#ifdef ARCH_avr
> + case bfd_arch_avr:
> + info->created_styled_output = true;
> + break;
> +#endif
> #ifdef ARCH_csky
> case bfd_arch_csky:
> info->symbol_is_valid = csky_symbol_is_valid;
> --
> 2.34.1
>
>
--
Marcus Nilsson
-
tel: +46(0)704911844
mail: marcus@landmarknilsson.se
github: github.com/metmo
linkedin: linkedin.com/in/landmarknilsson
next prev parent reply other threads:[~2022-06-17 8:57 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-06 19:11 Marcus Nilsson
2022-06-17 8:57 ` Marcus Nilsson [this message]
2022-06-29 17:20 ` [PING][PATCH] " Marcus Nilsson
2022-06-30 11:10 ` Nick Clifton
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=CAA1E49usMK+-_mrcGPVLGrDuR-Tc0ELgvn63QjVV151-KMSP+A@mail.gmail.com \
--to=brainbomb@gmail.com \
--cc=binutils@sourceware.org \
/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 read-only IMAP folder(s) and NNTP newsgroup(s).