adding custom instruction"push" for riscv toolchain

50 views
Skip to first unread message

Hager Rafaat

unread,
Jun 13, 2023, 9:00:08 PM6/13/23
to RISC-V SW Dev
hi, i am now adding push custom instruction to riscv32-gcc toolchain i will modify riscv-opc.c and riscv-opc.h and riscv.md for adding the functionalty of the push instruction and the functionality of the push is to saves the registers r1, [r5:r31] in the memory starting from location sp + 8 and with incrementing offset + 4 the rest of the register such that r5 will be saved in sp + 12 , r6 in sp + 16 , it does not take any operands or destination as every thisng is specified in the implementation of the hardware (processor ,memory) , so is these modifications are enough ? and when i modify the riscv-opc.c when i write the INSN_CLASS which one is suitable or do i need to define new one ?

Tommy Murphy

unread,
Jun 14, 2023, 5:20:48 AM6/14/23
to Hager Rafaat, RISC-V SW Dev
> i am now adding push custom instruction to riscv32-gcc toolchain 

If you search the issues (including the closed ones) here for something like "add new instruction" or "add custom instruction" you'll find some useful info/pointers about customising the toolchain.

* https://github.com/riscv-collab/riscv-gcc/issues

From: Hager Rafaat <hage...@gmail.com>
Sent: Wednesday, June 14, 2023 2:00:08 AM
To: RISC-V SW Dev <sw-...@groups.riscv.org>
Subject: [sw-dev] adding custom instruction"push" for riscv toolchain
 
hi, i am now adding push custom instruction to riscv32-gcc toolchain i will modify riscv-opc.c and riscv-opc.h and riscv.md for adding the functionalty of the push instruction and the functionality of the push is to saves the registers r1, [r5:r31] in the memory starting from location sp + 8 and with incrementing offset + 4 the rest of the register such that r5 will be saved in sp + 12 , r6 in sp + 16 , it does not take any operands or destination as every thisng is specified in the implementation of the hardware (processor ,memory) , so is these modifications are enough ? and when i modify the riscv-opc.c when i write the INSN_CLASS which one is suitable or do i need to define new one ?

--
You received this message because you are subscribed to the Google Groups "RISC-V SW Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sw-dev+un...@groups.riscv.org.
To view this discussion on the web visit https://groups.google.com/a/groups.riscv.org/d/msgid/sw-dev/014c8b9d-60f3-45b4-b2a6-2f672ba11dfdn%40groups.riscv.org.

Hager Rafaat

unread,
Jun 14, 2023, 4:21:51 PM6/14/23
to RISC-V SW Dev, tommy_...@hotmail.com, Hager Rafaat
i am trying to add a custom mov instruction that takes the value in the register rs2 and saves it in rd , asm: mov rd , rs2 i modified the riscv-opc.c by adding this line {"mov", 0, INSN_CLASS_I,"d,t",MATCH_MOV,MASK_MOV,match_opcode,0}, and modifying the riscv-opc.h by adding those lines #define MATCH_MOV 0x1F80 #define MASK_MOV 0xFE00707F and DECLARE_INSN(mov,MATCH_MOV,MASK_MOV) and modifying riscv.md by adding (define_insn "mov" [(set (match_operand:SI 0 "register_operand" "=r") (match_operand:SI 1 "register_operand" "r"))] "" "mov\t%0, %1" ) but it gives me the following error : Assembler messages: Error: internal: bad RISC-V opcode (mask error): mov d,s Fatal error: internal: broken assembler. No assembly attempted make[6]: *** [Makefile:397: lib_a-chk_fail.o] Error 1 make[6]: Leaving directory '/home/eman/riscv32_toolchain/build-newlib/riscv32-unknown-elf/newlib/libc/ssp' Making all in . make[6]: Entering directory '/home/eman/riscv32_toolchain/build-newlib/riscv32-unknown-elf/newlib/libc' rm -f libc.a rm -rf tmp mkdir tmp cd tmp; \ for i in argz/lib.a stdlib/lib.a ctype/lib.a search/lib.a stdio/lib.a string/lib.a signal/lib.a time/lib.a locale/lib.a reent/lib.a errno/lib.a misc/lib.a ssp/lib.a syscalls/lib.a machine/lib.a ; do \ riscv32-unknown-elf-ar x ../$i; \ done; \ riscv32-unknown-elf-ar rc ../libc.a *.o riscv32-unknown-elf-ar: ../argz/lib.a: No such file or directory riscv32-unknown-elf-ar: ../stdlib/lib.a: No such file or directory riscv32-unknown-elf-ar: ../ctype/lib.a: No such file or directory riscv32-unknown-elf-ar: ../search/lib.a: No such file or directory riscv32-unknown-elf-ar: ../stdio/lib.a: No such file or directory riscv32-unknown-elf-ar: ../string/lib.a: No such file or directory riscv32-unknown-elf-ar: ../signal/lib.a: No such file or directory riscv32-unknown-elf-ar: ../time/lib.a: No such file or directory riscv32-unknown-elf-ar: ../locale/lib.a: No such file or directory riscv32-unknown-elf-ar: ../reent/lib.a: No such file or directory riscv32-unknown-elf-ar: ../errno/lib.a: No such file or directory riscv32-unknown-elf-ar: ../misc/lib.a: No such file or directory riscv32-unknown-elf-ar: ../ssp/lib.a: No such file or directory riscv32-unknown-elf-ar: ../syscalls/lib.a: No such file or directory riscv32-unknown-elf-ar: ../machine/lib.a: No such file or directory riscv32-unknown-elf-ar: *.o: No such file or directory make[6]: *** [Makefile:1034: libc.a] Error 1 make[6]: Leaving directory '/home/eman/riscv32_toolchain/build-newlib/riscv32-unknown-elf/newlib/libc' make[5]: *** [Makefile:683: all-recursive] Error 1 make[5]: Leaving directory '/home/eman/riscv32_toolchain/build-newlib/riscv32-unknown-elf/newlib/libc' make[4]: *** [Makefile:641: all-recursive] Error 1 make[4]: Leaving directory '/home/eman/riscv32_toolchain/build-newlib/riscv32-unknown-elf/newlib' make[3]: *** [Makefile:452: all] Error 2 make[3]: Leaving directory '/home/eman/riscv32_toolchain/build-newlib/riscv32-unknown-elf/newlib' make[2]: *** [Makefile:8492: all-target-newlib] Error 2 make[2]: Leaving directory '/home/eman/riscv32_toolchain/build-newlib' make[1]: *** [Makefile:879: all] Error 2 make[1]: Leaving directory '/home/eman/riscv32_toolchain/build-newlib' make: *** [Makefile:606: stamps/build-newlib] Error 2
Reply all
Reply to author
Forward
0 new messages