public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Vijay Kumar Salian <salianvk@gmail.com>
To: Jim Wilson <jimw@sifive.com>, binutils@sourceware.org
Subject: Re: Help needed - to add custom instruction to binutils-gdb
Date: Mon, 21 Jun 2021 13:00:40 +0530	[thread overview]
Message-ID: <CAM-80khNBXN58E-FqZp2sBG5Nj+K7-+UT+LBYVB2Ke-UxByUMg@mail.gmail.com> (raw)
In-Reply-To: <CAFyWVaYBhS30pqYVtp9keTOuBwb+Kq=zaRRniJ-aVeDZhBqZbg@mail.gmail.com>

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},

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.

Please let me know if there is any order in which the new entries to be
inserted tinto *const struct riscv_opcode riscv_opcodes[]*?

Note: I added the binutils mailing list again.

--
Thanks & Regards,
Vijay




On Wed, 9 Jun 2021 at 01:13, Jim Wilson <jimw@sifive.com> wrote:

> On Tue, Jun 8, 2021 at 5:53 AM Vijay Kumar Salian <salianvk@gmail.com>
> wrote:
>
>> Thank you for the email.
>>
>
> You dropped the mailing list again.
>
>>
>> For this, I modified below 2 files:
>> 1. In file : riscv-gnu-toolchain/riscv-binutils/opcodes/riscv-opc.c,
>> added below line:
>> 2. In file :
>> riscv-gnu-toolchain/riscv-binutils/include/opcode/riscv-opc.h, added below
>> lines:
>>
>
> Those are the right files to modify.
>
> The I compiled the entire riscv-gnu-toolchain and tried running a C code
>> (using spike riscv simulator) that
>> has following instructions and it compiled without error and even I could
>> disassemble and see the instructions.
>>
>
> In the mailing list you said disassembling didn't work.  Now it does?  Did
> you change something?
>
>> Please let me know if this is the correct way to add new instructions. Am
>> I missing anything here or do I need to modify more files?
>>
>
> Yes, that looks like reasonable changes.
>
> Jim
>

  parent reply	other threads:[~2021-06-21  7:30 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 [this message]
2021-06-21  8:12         ` Nelson Chu
2021-06-21 11:51           ` Vijay Kumar Salian

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-80khNBXN58E-FqZp2sBG5Nj+K7-+UT+LBYVB2Ke-UxByUMg@mail.gmail.com \
    --to=salianvk@gmail.com \
    --cc=binutils@sourceware.org \
    --cc=jimw@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).