3 Star 20 Fork 6

yushulx / riscv-gnu-toolchain

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

RISC-V GNU Compiler Toolchain

此仓库的源码已经包含了riscv-gnu-toolchain源码中除了QEMU之外的子模块代码,方便网络不佳,又需要体验RISC-V的开发者。 如果GitHub访问速度好的,去https://github.com/riscv/riscv-gnu-toolchain 拿最新代码。 如果网速不好,又需要全部源码的,去https://gitee.com/mirrors/riscv-gnu-toolchain 拿每天同步的代码。

编译安装

接下来就按照官方教程编译。

依赖工具

Ubuntu

$ sudo apt-get install autoconf automake autotools-dev curl python3 libmpc-dev libmpfr-dev libgmp-dev gawk build-essential bison flex texinfo gperf libtool patchutils bc zlib1g-dev libexpat-dev

Fedora/CentOS/RHEL OS

$ sudo yum install autoconf automake python3 libmpc-devel mpfr-devel gmp-devel gawk  bison flex texinfo patchutils gcc gcc-c++ zlib-devel expat-devel

Arch Linux

$ pacman -Syyu autoconf automake curl python3 mpc mpfr gmp gawk build-essential bison flex texinfo gperf libtool patchutils bc zlib expat

OS X

$ brew install python3 gawk gnu-sed gmp mpfr libmpc isl zlib expat

编译GCC

编译riscv64-unknown-elf-gcc:

./configure --prefix=/opt/riscv
sudo make

编译64-bitriscv64-unknown-linux-gnu-gcc:

./configure --prefix=/opt/riscv
sudo make linux

编译32-bit:

./configure --prefix=/opt/riscv --with-arch=rv32gc --with-abi=ilp32d
sudo make linux

编译32-bit和64-bit:

./configure --prefix=/opt/riscv --enable-multilib
sudo make linux

这两个gcc的区别在于,elf-gcc是静态链接,linux-gnu-gcc是动态链接。

运行程序

Simulator

首先编译安装pk: https://github.com/riscv/riscv-pk。

然后编译安装spike:https://github.com/riscv/riscv-isa-sim

编译程序

riscv64-unknown-elf-gcc -o hello hello.c

运行

spike $(which pk) hello

Emulator

下载安装QEMU https://www.qemu.org/download/#source

参考教程运行模拟环境:https://wiki.qemu.org/Documentation/Platforms/RISCV

另外也可以使用tinyemu: https://bellard.org/tinyemu/

Fedora镜像获取:https://dl.fedoraproject.org/pub/alt/risc-v/repo/virt-builder-images/images/

Fedora-Minimal-Rawhide-20200108.n.0-sda.raw.xz 
Fedora-Minimal-Rawhide-20200108.n.0-fw_payload-uboot-qemu-virt-smode.elf

解压镜像:

unxz Fedora-Minimal-Rawhide-*-sda.raw.xz

启动模拟器:

 qemu-system-riscv64 \
   -nographic \
   -machine virt \
   -smp 4 \
   -m 2G \
   -kernel Fedora-Minimal-Rawhide-*-fw_payload-uboot-qemu-virt-smode.elf \
   -bios none \
   -object rng-random,filename=/dev/urandom,id=rng0 \
   -device virtio-rng-device,rng=rng0 \
   -device virtio-blk-device,drive=hd0 \
   -drive file=Fedora-Minimal-Rawhide-20200108.n.0-sda.raw,format=raw,id=hd0 \
   -device virtio-net-device,netdev=usernet \
   -netdev user,id=usernet,hostfwd=tcp::10000-:22

登录用户名riscv,密码fedora_rocks!

拷贝程序到模拟器中:

scp <user-name>@<ip address>:/<file path> ./

空文件

简介

取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/yushulx/riscv-gnu-toolchain.git
git@gitee.com:yushulx/riscv-gnu-toolchain.git
yushulx
riscv-gnu-toolchain
riscv-gnu-toolchain
master

搜索帮助