Rocket之添加指令
本帖最后由 新ちゃん 于 2020-8-20 22:31 编辑本文目录
[*]准备工作
[*]Rocket Chip 源码
[*]添加指令
[*]译码信号
[*]ALU
[*]工具链
[*]opcodes
[*]添加指令
[*]spike支持
[*]编译
[*]测试
[*]C源码
[*]spike 测试结果
[*]RocketChip测试结果
准备工作
[*]指令空间(找到一个未使用的)。opcode = 10101011
[*]指令功能。同或操作
Rocket Chip 源码添加指令
[*]位置:rocket-chip/src/main/scala/rocket/Instructions.scala
object Instructions {
...
def QIHAO = BitPat("b0000000??????????000?????1010111")
...
}
译码信号
[*]位置:rocket-chip/src/main/scala/rocket/IDecode.scala
class IDecode() {
table {
...
QIHAO-> List(Y,N,N,N,N,N,Y,Y,A2_RS2, A1_RS1, IMM_X, DW_XPR,FN_SOR, N,M_X, MT_X, N,N,N,N,N,N,Y,CSR.N,N,N,N,N),
...
}
}
ALU
[*]位置:rocket-chip/src/main/scala/rocket/ALU.scala
object ALU {
...
def FN_SOR= UInt(8)
...
}
class ALU {
...
val out = Mux(io.fn === FN_SOR, ~(io.in1 ^ io.in2), Mux(io.fn === FN_ADD || io.fn === FN_SUB, io.adder_out, shift_logic))
...
}
工具链
opcodes
[*]位置:rocket-chip/riscv-tools/riscv-opcodes/opcodes
qihao rd rs1 rs2 31..25=014..12=0 6..2=0x15 1..0=3
[*]在opcodes下执行make install
添加指令
[*]位置:riscv-tools/riscv-gnu-toolchain/riscv-binutils-gdb/include/opcode/riscv-opc.h
#define MATCH_QIHAO 0x57
#define MASK_QIHAO0xfe00707f
DECLARE_INSN(qihao, MATCH_QIHAO, MASK_QIHAO)
#define DECLARE_INSN(INSN_NAME, INSN_MATCH, INSN_MASK) \
static inline bool is_ ## INSN_NAME ## _insn (long insn) \
{ \
return (insn & INSN_MASK) == INSN_MATCH; \
}
[*]位置:riscv-tools/riscv-gnu-toolchain/riscv-binutils-gdb/opcodes/riscv-opc.c
const struct riscv_opcode riscv_opcodes[] = {
/* name, isa, operands, match, mask, match_func, pinfo.*/
{"qihao", "I", "d,s,t",MATCH_QIHAO, MASK_QIHAO, match_opcode, 0 },
}
spike支持
[*]位置:rocket-chip/riscv-tools/riscv-isa-sim/riscv/insns/qihao.h
WRITE_RD(sext_xlen(~(RS1 ^ RS2)));
[*]位置:rocket-chip/riscv-tools/riscv-isa-sim/riscv/riscv.mk.in
riscv_insn_list = \
qihao \编译
cd rocket-chip/riscv-tools/
./build.sh
测试
C源码
#include<stdio.h>
int main() {
int res = 0;
__asm__ __volatile__("li a2, 0x00ff");
__asm__ __volatile__("li a3, 0x0f0f");
__asm__ __volatile__("qihao %0, a2, a3":"=r"(res)); // 0xfffff00f
printf("%x\n", res);
return 0;
}
spike 测试结果
RocketChip测试结果
本篇完,感谢关注:RISC-V单片机中文网
页:
[1]