Riscv-gnu-toolchain build problem while adding custom instruction

HI,

I tried adding one custom instruction to existing riscv-gnu-toolchain. Below are the steps i followed. I basically want to add instruction ‘mod’(modulus)

  1. New instruction called 'mod is added to the existing riscv_opcodes structure. like below

{“mod”, 0, INSN_CLASS_I, “d,s,t”, MATCH_MOD, MASK_MOD, match_opcode, 0},
in riscv-gnu-toolchain\riscv-binutils\opcodes\riscv-opc.c

  1. I have defined MATCH_MOD and MASK_MODE as
    #define MATCH_MOD 0x200006b
    #define MASK_MOD 0xfe00707f

and added DECLARE_INSN(mod, MATCH_MOD, MASK_MOD)
in riscv-gnu-toolchain\riscv-binutils\include\opcode\riscv-opc.h

Now i tried to rebuild my gnu toolchain and i got following error

internal error: can’t hash `add’: exists
Assembler messages:
Fatal error: Broken assembler. No assembly attempted.

I got this error during build phase of newlib

here is the command-line option logged in config.log

/opt/riscv-gnu-toolchain/riscv-gnu-toolchain/riscv-newlib/newlib/configure --srcdir=/opt/riscv-gnu-toolchain/riscv-gnu-toolchain/build_custom/…/riscv-newlib/newlib --cache-file=./config.cache --with-newlib --enable-multilib --with-cross-host=x86_64-pc-linux-gnu --prefix=/opt/riscv32_custom --enable-newlib-io-long-double --enable-newlib-io-long-long --enable-newlib-io-c99-formats --enable-newlib-register-fini --program-transform-name=s&^&riscv32-unknown-elf-& --disable-option-checking --with-target-subdir=riscv32-unknown-elf --build=x86_64-pc-linux-gnu --host=riscv32-unknown-elf --target=riscv32-unknown-elf

Can u suggest me what is going wrong here ? Is there any other place i have to add the new instruction encoding ?

there is another file called riscv-opc.h and riscv-opc.c in \riscv-gdb\opcodes folder. should i also modify the structure table there also ?

basically i want disassembler to emit this new instruction.

The newlib build is the first time we try to use the just built assembler. If you just try running the assembler you will see that it errors every time it is run.

I would guess that there is something wrong with your patches. Maybe try a git diff to verify that you only have the changes that you think that you have. You might have accidentally modified something else. Your suggested changes appear to work for me.