From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oa1-x30.google.com (mail-oa1-x30.google.com [IPv6:2001:4860:4864:20::30]) by sourceware.org (Postfix) with ESMTPS id 69E41384D1B0 for ; Wed, 29 Jun 2022 17:20:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 69E41384D1B0 Received: by mail-oa1-x30.google.com with SMTP id 586e51a60fabf-fe023ab520so22289886fac.10 for ; Wed, 29 Jun 2022 10:20:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=CYaStIhWejP3WYPAJehPbACVL+8RVaPUqVqI7sEdJiI=; b=e+F/hOZHt4r87baM40kKHMLdi20fyTawGClyE0xVn+4oylZnHXN0wSyEmSUpNnwgXe Ps6xIzedNq2M4fW9l2Ih3W9Zap8X6uXTUzr+3ASRpVfaeyd1uc6ZN4QKFkC1LRtMe57+ s91JAc5UOi1CUALpydUjj8d7CKmOQk3TXYFLBKkc/fmOBtIUrMMnQEAZ40vD11GrJOoq ZUy+3LM0eS8UA2V8XVrKtjNiKilTeqB1FM0BzrtEoH0CTNfWe4+dOGVvtaG2cZ3ky8yw fcfXLU+aUTVdvZk4rwSWgrZwqqRbTSoGA8JVERLkOjE4MnbeVJwEFX1csWBBKlUgJOfS TihQ== X-Gm-Message-State: AJIora+gH4euqW3epsxIRu1nsUHz80SeC77ZkQ+ovIHPisCFeypl17cp f30WkddlhzeGN0RZXY8b+0vTcqm9w/TVaiy7RKEKC9qDvQ4= X-Google-Smtp-Source: AGRyM1u47hkDzEPSX68UBKIueioTazMSbUOh+15Z3vmvE3BQIFBJlSxeY9rD30FqtGzzDw4WQioVMXkdULSgo+DlNCw= X-Received: by 2002:a05:6870:51cb:b0:fb:5c97:bd1b with SMTP id b11-20020a05687051cb00b000fb5c97bd1bmr2552567oaj.104.1656523231727; Wed, 29 Jun 2022 10:20:31 -0700 (PDT) MIME-Version: 1.0 References: <20220606191118.550423-1-brainbomb@gmail.com> In-Reply-To: <20220606191118.550423-1-brainbomb@gmail.com> From: Marcus Nilsson Date: Wed, 29 Jun 2022 19:20:16 +0200 Message-ID: Subject: [PING][PATCH] opcodes/avr: Implement style support in the disassembler To: binutils@sourceware.org X-Spam-Status: No, score=-7.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, HTML_MESSAGE, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 29 Jun 2022 17:20:35 -0000 One more ping for this one Thanks, Marcus Nilsson On Mon, Jun 6, 2022 at 9:11 PM Marcus Nilsson 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