FPGA開発日記

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

QEMUに入門してみる(1. RISC-V用ビルドの確認)

QEMUソースコードGitHubからダウンロードして中身を見てみる。riscvと名のつくディレクトリがどの程度あるか探してみた。

$ find . -name riscv
./hw/riscv
./include/hw/riscv
./linux-user/riscv
./target/riscv
./tcg/riscv

ビルドするには以下を実行する。Sphinxのバージョンによっては--disable-werrorを必要とする。

$ ./configure --disable-werror --target=riscv64-softmmu
$ make -j$(nproc)

ここまででriscv64-softmmu/qemu-system-riscv64がビルドされた。riscv64-softmmuの定義はどこで行われているのだろう?

default-configs/riscv64-softmmu.mak
default-configs/riscv32-softmmu.mak

この辺かな?

  • default-configs/riscv32-softmmu.mak
CONFIG_SPIKE=y
CONFIG_SIFIVE_E=y
CONFIG_SIFIVE_U=y
CONFIG_RISCV_VIRT=y

うーん、何か違うような。

  • hw/riscv/Makefile.objs にオブジェクトファイルの定義がある。これでビルドするファイルを決めるのか。
obj-y += boot.o
obj-$(CONFIG_SPIKE) += riscv_htif.o
obj-$(CONFIG_HART) += riscv_hart.o
obj-$(CONFIG_SIFIVE_E) += sifive_e.o
obj-$(CONFIG_SIFIVE_E) += sifive_e_prci.o
obj-$(CONFIG_SIFIVE) += sifive_clint.o
obj-$(CONFIG_SIFIVE) += sifive_gpio.o
obj-$(CONFIG_SIFIVE) += sifive_plic.o
obj-$(CONFIG_SIFIVE) += sifive_test.o
obj-$(CONFIG_SIFIVE_U) += sifive_u.o
obj-$(CONFIG_SIFIVE_U) += sifive_u_otp.o
obj-$(CONFIG_SIFIVE_U) += sifive_u_prci.o
obj-$(CONFIG_SIFIVE) += sifive_uart.o
obj-$(CONFIG_SPIKE) += spike.o
obj-$(CONFIG_RISCV_VIRT) += virt.o

主要なソースファイルであるtarget/riscv/Makefiles.objsは以下のように定義されている。translate.oが重要なファイルのようだ。

obj-y += translate.o op_helper.o cpu_helper.o cpu.o csr.o fpu_helper.o gdbstub.o
obj-$(CONFIG_SOFTMMU) += pmp.o

ifeq ($(CONFIG_SOFTMMU),y)
obj-y += monitor.o
endif

DECODETREE = $(SRC_PATH)/scripts/decodetree.py

decode32-y = $(SRC_PATH)/target/riscv/insn32.decode
decode32-$(TARGET_RISCV64) += $(SRC_PATH)/target/riscv/insn32-64.decode

decode16-y = $(SRC_PATH)/target/riscv/insn16.decode
decode16-$(TARGET_RISCV32) += $(SRC_PATH)/target/riscv/insn16-32.decode
decode16-$(TARGET_RISCV64) += $(SRC_PATH)/target/riscv/insn16-64.decode

target/riscv/decode_insn32.inc.c: $(decode32-y) $(DECODETREE)
        $(call quiet-command, \
          $(PYTHON) $(DECODETREE) -o $@ --static-decode decode_insn32 \
          $(decode32-y), "GEN", $(TARGET_DIR)$@)

target/riscv/decode_insn16.inc.c: $(decode16-y) $(DECODETREE)
        $(call quiet-command, \
          $(PYTHON) $(DECODETREE) -o $@ --static-decode decode_insn16 \
          --insnwidth 16 $(decode16-y), "GEN", $(TARGET_DIR)$@)

target/riscv/translate.o: target/riscv/decode_insn32.inc.c \
        target/riscv/decode_insn16.inc.c