FPGA開発日記

カテゴリ別記事インデックス https://msyksphinz.github.io/github_pages , English Version https://fpgadevdiary.hatenadiary.com/

QEMUに入門してみる(8. translateに必要な関数の確認)

QEMUの続き。独自ターゲットでビルドしてみる。前回の続き。

gen_load()gen_store()で使用されている関数を定義しなければならない。

  • gen_get_gpr():GPRから値を取得する関数。
/* Wrapper for getting reg values - need to check of reg is zero since
 * cpu_gpr[0] is not actually allocated
 */
static inline void gen_get_gpr(TCGv t, int reg_num)
{
  if (reg_num == 0) {
    tcg_gen_movi_tl(t, 0);
  } else {
    tcg_gen_mov_tl(t, cpu_gpr[reg_num]);
  }
}
  • gen_set_gpr():GPRに値を設定する関数。
/* Wrapper for setting reg values - need to check of reg is zero since
 * cpu_gpr[0] is not actually allocated. this is more for safety purposes,
 * since we usually avoid calling the OP_TYPE_gen function if we see a write to
 * $zero
 */
static inline void gen_set_gpr(int reg_num_dst, TCGv t)
{
  if (reg_num_dst != 0) {
    tcg_gen_mov_tl(cpu_gpr[reg_num_dst], t);
  }
}

まだ足りないものがある。gen_helper_raise_exception()を定義する。

  • qemu/target/myriscvx/helper.h
/* Exceptions */
DEF_HELPER_2(raise_exception, noreturn, env, i32)

ここまでいろいろ定義して、一応ビルドが通るようになった。

  CC      myriscvx64-softmmu/target/myriscvx/cpu.o
  CC      myriscvx64-softmmu/target/myriscvx/cpu_helper.o
  CC      myriscvx64-softmmu/target/myriscvx/op_helper.o
  CC      myriscvx64-softmmu/target/myriscvx/translate.o
  CC      myriscvx64-softmmu/trace/control-target.o
  CC      myriscvx64-softmmu/trace/generated-helpers.o
  LINK    myriscvx64-softmmu/qemu-system-myriscvx64

Compilation finished at Sun Jul  5 22:46:14