修改RISCV工具链
第一步是安装RISCV工具链:
$ git clone https://github.com/riscv/riscv-tools.git
$ git submodule update --init --recursive
$ export RISCV=/path/to/install/riscv/toolchain
$ ./build.sh
第二步明确要添加的指令,以mod指令为例:
mod r1, r2, r3
Semantics:
R[r1] = R[r2] % R[r3]
第三步打开 riscv-opcodes/opcodes文件,在这里,将能够看到分配给各种指令的各种操作码和指令位。 为mod指令分配了一条未使用的指令:
sra rd rs1 rs2 31..25=32 14..12=5 6..2=0x0C 1..0=3
or rd rs1 rs2 31..25=0 14..12=6 6..2=0x0C 1..0=3
and rd rs1 rs2 31..25=0 14..12=7 6..2=0x0C 1..0=3
mod rd rs1 rs2 31..25=1 14..12=0 6..2=0x1A 1..0=3
addiw rd rs1 imm12 14..12=0 6..2=0x06 1..0=3
slliw rd rs1 31..25=0 shamtw 14..12=1 6..2=0x06 1..0=3
srliw rd rs1 31..25=0 shamtw 14..12=5 6..2=0x06 1..0=3
sraiw rd rs1 31..25=32 shamtw 14..12=5 6..2=0x06 1..0=3
第四步,运行下面的代码得到MOD的掩码和代码:
cat opcode