如何添加新指令并模拟它(尖峰)?

时间:2017-03-24 13:22:23

标签: gcc riscv

我想在RISCV ISA中添加新指令,我按照以下步骤操作:

  

模拟新指令。向模拟器添加指令需要两个步骤:

     
      
  1. 描述文件riscv/insns/<new_instruction_name>.h中的说明功能行为。检查该目录中的其他说明作为起点。
  2.   
  3. 将操作码和操作码掩码添加到riscv/opcodes.h。或者,将它添加到riscv-opcodes包中,它将为您执行此操作:$ cs ../riscv-opcodes; vi opcodes // add a line for the new instruction; make install
  4.   
  5. 重建总结者。
  6.   

enter image description here

我编写了简单的汇编代码来测试:

.file   "hello.c"
.text
.align  2
.globl  main
.type   main, @function
main:
   li   a0, 2
   mac  a1, a2, a3
   add  a0, a0, a1
.size main, .-main
.ident "GCC: (GNU)5.2.

enter image description here

但它无法识别新指令(mac a1,a2,a3)并显示错误消息:

$ riscv64-unknown-elf-gcc hello.s
...
hello.s:8: Error:unrecognized opcode `mac a1,a2,a3'

enter image description here

我该怎么办?

1 个答案:

答案 0 :(得分:1)

您的指令(https://github.com/riscv/riscv-isa-sim#simulating-a-new-instruction)用于将指令添加到模拟器,而不是用于as命令调用的汇编程序(binutils gas / gcc)。消息&#34; Error: unrecognized opcode 'mac a1,a2,a3'&#34;来自汇编程序工具,有代码来生成此错误:https://github.com/riscv/riscv-binutils-gdb/blob/master/gas/config/tc-riscv.c#L1187

/ *此例程将指令组装成二进制格式。作为一个    副作用,它将全局变量imm_reloc设置为类型    如果其中一个操作数是地址表达式,则重定位。 * /

static const char *
riscv_ip (char *str, struct riscv_cl_insn *ip, expressionS *imm_expr,
      bfd_reloc_code_real_type *imm_reloc)
...
  const char *error = "unrecognized opcode";
  for ( ; insn && insn->name && strcmp (insn->name, str) == 0; insn++)
  {
  ...
  }
out:
  ...
  return error;

您可以将新指令编码为原始字节以使用当前的汇编程序;或者您需要更改riscv/riscv-tools的汇编程序,方法是更改​​riscv/riscv-opcodes/中的操作码列表并使用新的riscv-opcodes重建您的riscv-binutils(https://github.com/riscv/riscv-binutils-gdb)。

相关问题