From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oa1-x2a.google.com (mail-oa1-x2a.google.com [IPv6:2001:4860:4864:20::2a]) by sourceware.org (Postfix) with ESMTPS id 8858F3858D1E for ; Tue, 31 Jan 2023 01:47:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8858F3858D1E Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=rivosinc.com Received: by mail-oa1-x2a.google.com with SMTP id 586e51a60fabf-15085b8a2f7so17630284fac.2 for ; Mon, 30 Jan 2023 17:47:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20210112.gappssmtp.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=pFQ06DtvdP2Sma2wGlrYI9cySmnis5VqIKQ9wWuqweI=; b=YUmoK1vlU9IUuTRapmoptuMUM7G+eoKs2q83kGatk9oCEg7OtQB3gSkOjqdbyssLFP RitA4vw4CEqlgKFZOO5mUg+fw5QndJG7TBGErniTnVR/gUuVN8pRufbnXJddHDGSBRn+ Iy9qCe6jZUYAG6jWfZglTaQo8V0qVOJswOn9BcmBB/SyBoq3bZoQSHT6ZSrrkM8GIt9Y acMj5J8xBB42I+ALdmRlBHgFmIjlzbWcC8z0rxIohQnUtsKE3zC3RpAGOd3IAUq5m6W+ ovK6Zra2iCylJWsFbZQJYIPuc84KbXiP5Z5ZNHS24ccDrbGtUs/9T7fuqqgAhwVVfPZl oblQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=pFQ06DtvdP2Sma2wGlrYI9cySmnis5VqIKQ9wWuqweI=; b=MhjfR1jg/lug3lxo7381w48ZkckKs3yAwRjsFAtJaOv7sHRVsAbMeyjqSSKICBdqcF 03O/nhhTwBdE5leSs6xKDoINFWe3m5ASvP2ziUiyUu7u9kYZfZjJGXXVvCeLh/iNSNJa L/KATm+zIdPFocGaEdsrJZDDJcf8A4R+z1RB0/gVqQiKVD6tDqG7ucD71fH0rlsTJdpn Iy2akvy19wdBTo43ljoz4YrXFAqLRwvaXi+bPQSKrz6+Y9Xjnr8++x+KWZQdCsnByaOS uHI7M6wtQwim/g7RZ7TkCgy1HJj2Uf2Ae/YHqZJUktk5Ny3WXIdwyu0+vNO0Szmsgr2k 2FCw== X-Gm-Message-State: AO0yUKU8CeVTXm5AeBc2FeX05JHm42JhGb6ztOv+Wn1VAY/cT/gy1cGK rnOgJoDjFt3YAvdni2WJ0GK6qJmbX/h+3fksoY4eiA== X-Google-Smtp-Source: AK7set/vVpMA5gzWSAtSl2n3N5PvUaH2fw4hzwyxoV57rt2SkAZhluFgHU8FtT27bGnAuyfa/CnxvmRRBqRix+mansQ= X-Received: by 2002:a05:6870:d79c:b0:163:4ba0:fc7c with SMTP id bd28-20020a056870d79c00b001634ba0fc7cmr1988135oab.244.1675129631364; Mon, 30 Jan 2023 17:47:11 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Nelson Chu Date: Tue, 31 Jan 2023 09:47:00 +0800 Message-ID: Subject: Re: [PATCH v2] RISC-V: don't disassemble unrecognized insns as .byte To: Jan Beulich Cc: Binutils , Palmer Dabbelt , Andrew Waterman , Jim Wilson , Kito Cheng Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-3.2 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,KAM_LOTSOFHASH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Yeah, I think this is what we need and should be what most people expect, so it looks good to me. Thanks Nelson On Mon, Jan 30, 2023 at 10:40 PM Jan Beulich wrote: > > Insn width granularity being 16 bits, producing byte granular output > isn't very useful. With there being a way to specific otherwise > unknown insns to the assembler, use that same representation (to be > precise: its , flavor) for disassembly. > --- > v2: Switch to using .insn. > > --- a/binutils/testsuite/binutils-all/riscv/unknown.d > +++ b/binutils/testsuite/binutils-all/riscv/unknown.d > @@ -1,11 +1,11 @@ > #as: -march=rv32ic > #objdump: -d > # Test the disassembly of unknown instruction encodings, specifically, > -# ensure that we generate a .?byte opcode. > +# ensure that we generate a .insn directive. > > #... > Disassembly of section \.text: > > [0-9a-f]+ <\.text>: > - [0-9a-f]+: 0052018b \.4byte 0x52018b > - [0-9a-f]+: 9c45 \.2byte 0x9c45 > + [0-9a-f]+: 0052018b \.insn 4, 0x0052018b > + [0-9a-f]+: 9c45 \.insn 2, 0x9c45 > --- a/gas/testsuite/gas/riscv/insn.d > +++ b/gas/testsuite/gas/riscv/insn.d > @@ -92,25 +92,25 @@ Disassembly of section .text: > [^:]+:[ ]+607f 0000 0000 0000[ ]+[._a-z].* > [^:]+:[ ]+0000 0000 0000 0000 ? > [^:]+:[ ]+0000 0000 0000 ? > -[^:]+:[ ]+007f 0000 0000 0000[ ]+\.byte[ ]+0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80 > +[^:]+:[ ]+007f 0000 0000 0000[ ]+\.insn[ ]+10, +0x8000000000000000007f > [^:]+:[ ]+8000 ? > -[^:]+:[ ]+007f 0000 0000 0000[ ]+\.byte[ ]+0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80 > +[^:]+:[ ]+007f 0000 0000 0000[ ]+\.insn[ ]+10, +0x8000000000000000007f > [^:]+:[ ]+8000 ? > -[^:]+:[ ]+607f 89ab 4567 0123[ ]+\.byte[ ]+0x7f, 0x60, 0xab, 0x89, 0x67, 0x45, 0x23, 0x01, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 > +[^:]+:[ ]+607f 89ab 4567 0123[ ]+\.insn[ ]+22, 0xfedcba98765432100123456789ab607f > [^:]+:[ ]+3210 7654 ba98 fedc ? > [^:]+:[ ]+0000 0000 0000 ? > -[^:]+:[ ]+607f 89ab 4567 0123[ ]+\.byte[ ]+0x7f, 0x60, 0xab, 0x89, 0x67, 0x45, 0x23, 0x01, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 > +[^:]+:[ ]+607f 89ab 4567 0123[ ]+\.insn[ ]+22, 0xfedcba98765432100123456789ab607f > [^:]+:[ ]+3210 7654 ba98 fedc ? > [^:]+:[ ]+0000 0000 0000 ? > -[^:]+:[ ]+607f 33cc 55aa cdef[ ]+\.byte[ ]+0x7f, 0x60, 0xcc, 0x33, 0xaa, 0x55, 0xef, 0xcd, 0xab, 0x89, 0x67, 0x45, 0x23, 0x01, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0x00 > +[^:]+:[ ]+607f 33cc 55aa cdef[ ]+\.insn[ ]+22, 0x00dcba98765432100123456789abcdef55aa33cc607f > [^:]+:[ ]+89ab 4567 0123 3210 ? > [^:]+:[ ]+7654 ba98 00dc ? > -[^:]+:[ ]+607f 33cc 55aa cdef[ ]+\.byte[ ]+0x7f, 0x60, 0xcc, 0x33, 0xaa, 0x55, 0xef, 0xcd, 0xab, 0x89, 0x67, 0x45, 0x23, 0x01, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0x00 > +[^:]+:[ ]+607f 33cc 55aa cdef[ ]+\.insn[ ]+22, 0x00dcba98765432100123456789abcdef55aa33cc607f > [^:]+:[ ]+89ab 4567 0123 3210 ? > [^:]+:[ ]+7654 ba98 00dc ? > -[^:]+:[ ]+607f 33cc 55aa cdef[ ]+\.byte[ ]+0x7f, 0x60, 0xcc, 0x33, 0xaa, 0x55, 0xef, 0xcd, 0xab, 0x89, 0x67, 0x45, 0x23, 0x01, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe > +[^:]+:[ ]+607f 33cc 55aa cdef[ ]+\.insn[ ]+22, 0xfedcba98765432100123456789abcdef55aa33cc607f > [^:]+:[ ]+89ab 4567 0123 3210 ? > [^:]+:[ ]+7654 ba98 fedc ? > -[^:]+:[ ]+607f 33cc 55aa cdef[ ]+\.byte[ ]+0x7f, 0x60, 0xcc, 0x33, 0xaa, 0x55, 0xef, 0xcd, 0xab, 0x89, 0x67, 0x45, 0x23, 0x01, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe > +[^:]+:[ ]+607f 33cc 55aa cdef[ ]+\.insn[ ]+22, 0xfedcba98765432100123456789abcdef55aa33cc607f > [^:]+:[ ]+89ab 4567 0123 3210 ? > [^:]+:[ ]+7654 ba98 fedc ? > --- a/gas/testsuite/gas/riscv/insn-na.d > +++ b/gas/testsuite/gas/riscv/insn-na.d > @@ -73,11 +73,11 @@ Disassembly of section .text: > [^:]+:[ ]+007f 0000 0000 0000 0000[ ]+[._a-z].* > [^:]+:[ ]+0000107f 00000000 00000000[ ]+[._a-z].* > [^:]+:[ ]+607f 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000[ ]+[._a-z].* > -[^:]+:[ ]+007f 0000 0000 0000 8000[ ]+\.byte[ ]+0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80 > -[^:]+:[ ]+007f 0000 0000 0000 8000[ ]+\.byte[ ]+0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80 > -[^:]+:[ ]+607f 89ab 4567 0123 3210 7654 ba98 fedc 0000 0000 0000[ ]+\.byte[ ]+0x7f, 0x60, 0xab, 0x89, 0x67, 0x45, 0x23, 0x01, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 > -[^:]+:[ ]+607f 89ab 4567 0123 3210 7654 ba98 fedc 0000 0000 0000[ ]+\.byte[ ]+0x7f, 0x60, 0xab, 0x89, 0x67, 0x45, 0x23, 0x01, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 > -[^:]+:[ ]+607f 33cc 55aa cdef 89ab 4567 0123 3210 7654 ba98 00dc[ ]+\.byte[ ]+0x7f, 0x60, 0xcc, 0x33, 0xaa, 0x55, 0xef, 0xcd, 0xab, 0x89, 0x67, 0x45, 0x23, 0x01, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0x00 > -[^:]+:[ ]+607f 33cc 55aa cdef 89ab 4567 0123 3210 7654 ba98 00dc[ ]+\.byte[ ]+0x7f, 0x60, 0xcc, 0x33, 0xaa, 0x55, 0xef, 0xcd, 0xab, 0x89, 0x67, 0x45, 0x23, 0x01, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0x00 > -[^:]+:[ ]+607f 33cc 55aa cdef 89ab 4567 0123 3210 7654 ba98 fedc[ ]+\.byte[ ]+0x7f, 0x60, 0xcc, 0x33, 0xaa, 0x55, 0xef, 0xcd, 0xab, 0x89, 0x67, 0x45, 0x23, 0x01, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe > -[^:]+:[ ]+607f 33cc 55aa cdef 89ab 4567 0123 3210 7654 ba98 fedc[ ]+\.byte[ ]+0x7f, 0x60, 0xcc, 0x33, 0xaa, 0x55, 0xef, 0xcd, 0xab, 0x89, 0x67, 0x45, 0x23, 0x01, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe > +[^:]+:[ ]+007f 0000 0000 0000 8000[ ]+\.insn[ ]+10, +0x8000000000000000007f > +[^:]+:[ ]+007f 0000 0000 0000 8000[ ]+\.insn[ ]+10, +0x8000000000000000007f > +[^:]+:[ ]+607f 89ab 4567 0123 3210 7654 ba98 fedc 0000 0000 0000[ ]+\.insn[ ]+22, 0xfedcba98765432100123456789ab607f > +[^:]+:[ ]+607f 89ab 4567 0123 3210 7654 ba98 fedc 0000 0000 0000[ ]+\.insn[ ]+22, 0xfedcba98765432100123456789ab607f > +[^:]+:[ ]+607f 33cc 55aa cdef 89ab 4567 0123 3210 7654 ba98 00dc[ ]+\.insn[ ]+22, 0x00dcba98765432100123456789abcdef55aa33cc607f > +[^:]+:[ ]+607f 33cc 55aa cdef 89ab 4567 0123 3210 7654 ba98 00dc[ ]+\.insn[ ]+22, 0x00dcba98765432100123456789abcdef55aa33cc607f > +[^:]+:[ ]+607f 33cc 55aa cdef 89ab 4567 0123 3210 7654 ba98 fedc[ ]+\.insn[ ]+22, 0xfedcba98765432100123456789abcdef55aa33cc607f > +[^:]+:[ ]+607f 33cc 55aa cdef 89ab 4567 0123 3210 7654 ba98 fedc[ ]+\.insn[ ]+22, 0xfedcba98765432100123456789abcdef55aa33cc607f > --- a/opcodes/riscv-dis.c > +++ b/opcodes/riscv-dis.c > @@ -650,7 +650,8 @@ riscv_disassemble_insn (bfd_vma memaddr, > static bool init = false; > static const struct riscv_opcode *riscv_hash[OP_MASK_OP + 1]; > struct riscv_private_data *pd; > - int insnlen; > + int insnlen, i; > + bool printed; > > #define OP_HASH_IDX(i) ((i) & (riscv_insn_length (i) == 2 ? 0x3 : OP_MASK_OP)) > > @@ -666,8 +667,6 @@ riscv_disassemble_insn (bfd_vma memaddr, > > if (info->private_data == NULL) > { > - int i; > - > pd = info->private_data = xcalloc (1, sizeof (struct riscv_private_data)); > pd->gp = 0; > pd->print_addr = 0; > @@ -783,37 +782,28 @@ riscv_disassemble_insn (bfd_vma memaddr, > } > } > > - /* We did not find a match, so just print the instruction bits. */ > + /* We did not find a match, so just print the instruction bits in > + the shape of an assembler .insn directive. */ > info->insn_type = dis_noninsn; > - switch (insnlen) > + (*info->fprintf_styled_func) > + (info->stream, dis_style_assembler_directive, ".insn"); > + (*info->fprintf_styled_func) (info->stream, dis_style_text, "\t"); > + (*info->fprintf_styled_func) (info->stream, dis_style_immediate, > + "%d", insnlen); > + (*info->fprintf_styled_func) (info->stream, dis_style_text, ", "); > + (*info->fprintf_styled_func) (info->stream, dis_style_immediate, "0x"); > + for (i = insnlen, printed = false; i >= 2; ) > { > - case 2: > - case 4: > - case 8: > - (*info->fprintf_styled_func) > - (info->stream, dis_style_assembler_directive, ".%dbyte", insnlen); > - (*info->fprintf_styled_func) (info->stream, dis_style_text, "\t"); > + i -= 2; > + word = bfd_get_bits (packet + i, 16, false); > + if (!word && !printed) > + continue; > + > (*info->fprintf_styled_func) (info->stream, dis_style_immediate, > - "0x%llx", (unsigned long long) word); > - break; > - default: > - { > - int i; > - (*info->fprintf_styled_func) > - (info->stream, dis_style_assembler_directive, ".byte"); > - (*info->fprintf_styled_func) (info->stream, dis_style_text, "\t"); > - for (i = 0; i < insnlen; ++i) > - { > - if (i > 0) > - (*info->fprintf_styled_func) (info->stream, dis_style_text, > - ", "); > - (*info->fprintf_styled_func) (info->stream, dis_style_immediate, > - "0x%02x", > - (unsigned int) (*packet++)); > - } > - } > - break; > + "%04x", (unsigned int) word); > + printed = true; > } > + > return insnlen; > } >