有人预言,RISC-V或将是继Intel和Arm之后的第三大主流处理器体系。欢迎访问全球首家只专注于RISC-V单片机行业应用的中文网站
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
本帖最后由 新ちゃん 于 2020-8-20 22:31 编辑
本文目录
准备工作- 指令空间(找到一个未使用的)。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=0 14..12=0 6..2=0x15 1..0=3
复制代码
添加指令
- 位置:riscv-tools/riscv-gnu-toolchain/riscv-binutils-gdb/include/opcode/riscv-opc.h
- #define MATCH_QIHAO 0x57
- #define MASK_QIHAO 0xfe00707f
- 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单片机中文网
|