2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

RISC-Vの本を買ったので、自宅のIntelマシンにエミュレート環境を作ることにしました。

CPU: Intel(R) Core(TM) i7-9700 CPU @ 3.00GHz
OS: Ubuntu 22.04

ホストの設定:QEMUのインストール

今回もQEMUで仮想コンテナを動かすことにしました。
ホストにQEMUのパッケージをインストールします。

$ apt install -y qemu-user-static

qemu-riscv64がenabledになっていることを確認します。

$ cat /proc/sys/fs/binfmt_misc/qemu-riscv64
enabled
interpreter /usr/libexec/qemu-binfmt/riscv64-binfmt-P
flags: POCF
offset 0
magic 7f454c460201010000000000000000000200f300
mask ffffffffffffff00fffffffffffffffffeffffff

コンテナの起動と動作確認

イメージはriscv64/ubuntuを使うことにしました。

$ docker run -it riscv64/ubuntu:22.04 /bin/bash

これで、QEMUエミュレートのRISC-V仮想コンテナができました。
RISC-VのGNUコンパイラ(GCC)は通常のaptでインストールできます。

$ apt install -y gcc

試しに以下のコードをコンパイルしてみます。

# a.c
#include <stdio.h>
int main(void) {
  printf("Hello RISC-V!\n");
  return 0;
}
$ gcc -O2 a.c

実行バイナリがRISC-Vに対応していることがわかります。

$ objdump -d a.out | grep format
a.out:     file format elf64-littleriscv

実行もできました。

$ ./a.out 
Hello RISC-V!
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?