Help needed - to add custom instruction to binutils-gdb

Vijay Kumar Salian salianvk@gmail.com
Mon Jun 21 07:30:40 GMT 2021


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
>


More information about the Binutils mailing list