public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Vijay Kumar Salian <salianvk@gmail.com>
To: Nelson Chu <nelson.chu@sifive.com>
Cc: Jim Wilson <jimw@sifive.com>, Binutils <binutils@sourceware.org>
Subject: Re: Help needed - to add custom instruction to binutils-gdb
Date: Mon, 21 Jun 2021 17:21:11 +0530	[thread overview]
Message-ID: <CAM-80ki5_zewLxSJreHd8UptwrprMDb+c37NzmFwQ6z7S8ds2A@mail.gmail.com> (raw)
In-Reply-To: <CAJYME4GxkwJotJ=7wEGmfM9MM3bxamCi35dyTFGKJMCM5aa+WA@mail.gmail.com>

Hi,

Thank you for the email.

Does the "encoding overlap" mean that the *MATCH_** macro values of 2
instructions are the same?
I have to check this once since I have added other instructions too.

I am using the riscv toolchain from this link:
https://github.com/riscv/riscv-gnu-toolchain
I hope this is the right toolchain for risc-v.

--
Thanks & Regards,
Vijay


On Mon, 21 Jun 2021 at 13:42, Nelson Chu <nelson.chu@sifive.com> wrote:

> On Mon, Jun 21, 2021 at 3:31 PM Vijay Kumar Salian via Binutils
> <binutils@sourceware.org> wrote:
> >
> > Hi,
> >
> > Below are the steps that I followed to add new custom instructions to
> > binutils.
> >
> > 1. Identified the instruction to add as "z.rol".
> >
> > 2. Add the below match and mask macros to riscv-gnu-toolchain/riscv-
> > binutils/include/opcode/riscv-opc.h
> > #define MATCH_Z_ROL 0x6057
> > #define MASK_Z_ROL  0xfe00707f
> >
> > 3. Add the below macro to riscv-gnu-toolchain/riscv-
> > binutils/include/opcode/riscv-opc.h
> > DECLARE_INSN(z_rol, MATCH_Z_ROL, MASK_Z_ROL)
> >
> > 4. Add new entry into const struct riscv_opcode riscv_opcodes[] in file
> > riscv-gnu-toolchain/riscv-binutils/opcodes/riscv-opc.c
> >
> > {"z.rol",       0, INSN_CLASS_I, "d,s,t", MATCH_Z_ROL, MASK_Z_ROL,
> > match_opcode, 0},
>
> The steps are correct.
>
> > 5. Compile the toolchain and test the assembly code with new
> instructions.
> >
> > The new instruction addition worked ONLY when the new entries were made
> at
> > the top of *const struct riscv_opcode riscv_opcodes[]*. But when I tried
> to
> > add the new entries at the *end* of *const struct riscv_opcode
> > riscv_opcodes[],* then toolchain compilation gave a lot of errors during
> > compilation and some of the GCC tools did not get compiled.
>
> The order does affect the results, but the premise is that the
> encoding has overlap, or the new instructions are the aliases of
> others which had existed.  I can get your expected result when adding
> the z.rol at the end of riscv_opcodes, so it should not be the order
> problem for your example.
>
> nelson@LAPTOP-QFSGI1F2:~/test$ cat tmp.s
> .word   0x6057
> z.rol   a0, a1, a2
> nelson@LAPTOP-QFSGI1F2:~/test$ riscv64-unknown-elf-as tmp.s -o tmp.o
> nelson@LAPTOP-QFSGI1F2:~/test$ riscv64-unknown-elf-objdump -d tmp.o
>
> tmp.o:     file format elf64-littleriscv
>
>
> Disassembly of section .text:
>
> 0000000000000000 <.text>:
>    0:   00006057                z.rol   zero,zero,zero
>    4:   00c5e557                z.rol   a0,a1,a2
>
>
> Thanks
> Nelson
>

      reply	other threads:[~2021-06-21 11:51 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-06  1:33 Vijay Kumar Salian
2021-06-07 18:40 ` Jim Wilson
     [not found]   ` <CAM-80kgSs7XOmdCA7_0ehcbuUKpAJf2hwQej7J03FR5zr4eEQg@mail.gmail.com>
     [not found]     ` <CAFyWVaYBhS30pqYVtp9keTOuBwb+Kq=zaRRniJ-aVeDZhBqZbg@mail.gmail.com>
2021-06-21  7:30       ` Vijay Kumar Salian
2021-06-21  8:12         ` Nelson Chu
2021-06-21 11:51           ` Vijay Kumar Salian [this message]

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=CAM-80ki5_zewLxSJreHd8UptwrprMDb+c37NzmFwQ6z7S8ds2A@mail.gmail.com \
    --to=salianvk@gmail.com \
    --cc=binutils@sourceware.org \
    --cc=jimw@sifive.com \
    --cc=nelson.chu@sifive.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 read-only IMAP folder(s) and NNTP newsgroup(s).