2017-03-24 44 views
1

私は手順に従って、RISCV ISAに新しい命令を追加したい:新しい命令を追加してシミュレートする方法(スパイク)?

Simulating a New Instruction. Adding an instruction to the simulator requires two steps:

  1. Describe the instructions's functional behavior in the file riscv/insns/<new_instruction_name>.h . Examine other instructions in that directory as a starting point.
  2. Add the opcode and opcode mask to riscv/opcodes.h . Alternatively, add it to the riscv-opcodes package, and it will do so for you: $ cs ../riscv-opcodes ; vi opcodes // add a line for the new instruction ; make install
  3. Rebuild the sumulator.

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)を認識できませんssage:

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

enter image description here

私はどうすればよいですか?

+0

スクリーンショットではありません。あなたは['' riscv/riscv-tools'](https://github.com/riscv/riscv-tools)のアセンブラを変更する必要があります。メッセージは "エラー:認識できないオペコード\' mac a1、a2、a3 "そこからです。このリストは['riscv/riscv-opcodes /'](https://github.com/riscv/riscv-opcodes)にあり、実際のエラーメッセージはriscv-binutils - gas https://github.com/riscvからです/riscv-binutils-gdb/blob/master/gas/config/tc-riscv.c#L1187 – osgx

+0

次回はスクリーンショットの代わりにテキストを投稿します。ご連絡ありがとうございます – jjlin

+0

質問に使用された外部リソースへの正確なリンクを投稿すると役立つことがあります(https://github.com/riscv/riscv-isa-sim#simulating-a-new-instruction、テキストの部分的なスクリーンショットではありません)。私はこの質問のためにイメージ - >テキスト変換を修正しました。 – osgx

答えて

1

あなたの命令は(https://github.com/riscv/riscv-isa-sim#simulating-a-new-instruction)シミュレータに、ではないあなたのgccコマンドによって呼び出されるアセンブラ(binutilsのas/gas)に指示を追加するためです。メッセージ「Error: unrecognized opcode 'mac a1,a2,a3'」はアセンブラツールのものです。このエラーを生成するコードがあります。https://github.com/riscv/riscv-binutils-gdb/blob/master/gas/config/tc-riscv.c#L1187

/*このルーチンは、命令をバイナリ形式にアセンブルします。 副作用として、オペランドの1つがアドレス式であれば、グローバル変数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-opcodes/に変更し、riscv-binutils(https://github.com/riscv/riscv-binutils-gdb)を新しいriscv-opcodeで再構築して、アセンブラriscv/riscv-toolsを変更する必要があります。

+0

返信ありがとうございます、私はすでに[risv/riscv-opcodes /](https://github.com/riscv/riscv-opcodes/tree/7650b391d47dd0b73d541d39c48041aa53517973)のオペコードリストを変更してインストールします。私はまた、ファイル[riscv/insns /](https://github.com/riscv/riscv-isa-sim/tree/master/riscv/insns)で命令の機能的な振る舞いについて説明しました。 最後に、私は[riscv-binutils-gdb/opcodes/riscv-opc.c](https://github.com/riscv/riscv-binutils-gdb/blob/riscv-next/opcodes/riscv- opc.c)。 しかしそれはまだ私にエラーを与えます(私はgnu-tool-chainを再構築できません)。間違っているステップはありますか? – jjlin

+0

jjlin、あなたが間違った質問を作成したときに間違ったステップがありました。この質問では、シミュレータを変更するための指示のみをリンクしました。 gnu toolchainのリビルドエラーは別のエラーです(それについてさらに詳しく知りたい)。フリーでこのようなエラーをデバッグするのは難しいです(次にstackoverflowに関するあなたの質問はofftopicとして閉じられるかもしれません)。カスタムの変更を行う前に、修正されていないriscvツールチェーンから始め、それらを再構築する方法を学んでください(他のOSのヘルプ、最近の指示を見つけるでしょう)。 – osgx

関連する問題