title: How to add new instruction and simulate it(spike)?
body: <p>I want to add new instruction in the RISCV ISA, I follow the steps:</p>
  
  <blockquote>
    <p>Simulating a New Instruction. Adding an instruction to the simulator requires two steps:</p>
    
    <ol>
    <li>Describe the instructions's functional behavior in the file <code>riscv/insns/&lt;new_instruction_name&gt;.h</code>. Examine other instructions in that directory as a starting point.</li>
    <li>Add the opcode and opcode mask to <code>riscv/opcodes.h</code>. Alternatively, add it to the riscv-opcodes package, and it will do so for you: <code>$ cs ../riscv-opcodes</code>; <code>vi opcodes // add a line for the new instruction</code>; <code>make install</code></li>
    <li>Rebuild the sumulator.</li>
    </ol>
  </blockquote>
  
  <p><a href="https://i.stack.imgur.com/mbnPC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mbnPC.png" alt="enter image description here"></a></p>
  
  <p>And I write the simple assembly code to test:</p>
  
  <pre><code>.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.
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/qZxSI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/qZxSI.png" alt="enter image description here"></a></p>
  
  <p>But it can't recognize the new instruction (<code>mac a1,a2,a3</code>) with error message:</p>
  
  <pre><code>$ riscv64-unknown-elf-gcc hello.s
  ...
  hello.s:8: Error:unrecognized opcode `mac a1,a2,a3'
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/aZfte.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/aZfte.png" alt="enter image description here"></a></p>
  
  <p>How should I do?</p>