risc-v gcc 工具链编译:
git clone --recursive https://github.com/riscv/riscv-gnu-toolchain.git
cd riscv-gnu-toolchain
mkdir build; cd build
../configure --prefix=$RISCV --enable-multilib
make -j4
make完成之后在 /bin 目录(因为$RISCV没有赋值导致安装到了默认目录/bin)安装了工具链文件:
/bin/riscv64-unknown-elf-ranlib
/bin/riscv64-unknown-elf-objdump
/bin/riscv64-unknown-elf-c++
/bin/riscv64-unknown-elf-c++filt
/bin/riscv64-unknown-elf-strings
/bin/riscv64-unknown-elf-ld
/bin/riscv64-unknown-elf-cpp
/bin/riscv64-unknown-elf-elfedit
/bin/riscv64-unknown-elf-as
/bin/riscv64-unknown-elf-nm
/bin/riscv64-unknown-elf-strip
/bin/riscv64-unknown-elf-gcov-tool
/bin/riscv64-unknown-elf-objcopy
/bin/riscv64-unknown-elf-size
/bin/riscv64-unknown-elf-gcc-ranlib
/bin/riscv64-unknown-elf-run
/bin/riscv64-unknown-elf-gprof
/bin/riscv64-unknown-elf-gcc-8.2.0
/bin/riscv64-unknown-elf-gcov
/bin/riscv64-unknown-elf-gcc
/bin/riscv64-unknown-elf-g++
/bin/riscv64-unknown-elf-gcc-ar
/bin/riscv64-unknown-elf-ld.bfd
/bin/riscv64-unknown-elf-gcc-nm
/bin/riscv64-unknown-elf-addr2line
/bin/riscv64-unknown-elf-readelf
/bin/riscv64-unknown-elf-gdb
/bin/riscv64-unknown-elf-ar
/bin/riscv64-unknown-elf-gcov-dump
参考1: https://www.librecores.org/codelec/riscv-sodor
参考2: https://www.cnblogs.com/javaIOException/p/7525828.html
参考3: https://purplepalmdash.github.io/2013/07/08/yong-qemumo-ni-arm-1/
离线
编译qemu模拟器:
sudo apt-get install libpixman-1-dev
git clone https://github.com/riscv/riscv-qemu.git
cd riscv-qemu/
git checkout riscv-qemu-3.0
./configure
make -j4
make install ###安装
离线
一个最简单的 RISC-V 汇编程序 test1.S:
loop:
j loop
编译指令:
riscv64-unknown-elf-gcc -save-temps -nostdlib -nostartfiles -ffreestanding -o test1 test1.S
模拟器运行:
qemu-riscv64 test1 -nographic
反汇编:
root@ubuntu:/opt/test# riscv64-unknown-elf-objdump -S test1
test1: file format elf64-littleriscv
Disassembly of section .text:
0000000000010078 <loop>:
10078: a001 j 10078 <loop>
离线
test1.S
loop:
nop
nop
nop
nop
j loop
编译(带调试符号):
riscv64-unknown-elf-gcc -save-temps -nostdlib -nostartfiles -ffreestanding -o test1 test1.S -g
启动带调试虚拟机:
qemu-riscv64 -singlestep -g 12345 test1 -nographic
远程调试:
riscv64-unknown-elf-gdb
参考1: http://doppioandante.github.io/2015/07/10/Simple-ARM-programming-on-linux.html
离线
为了把这个RISCV Linux 跑起来
需要先构建Linux工具链
git clone --recursive https://github.com/riscv/riscv-gnu-toolchain
cd riscv-gnu-toolchain
./configure --prefix=/usr/local/riscv-tools/
make
参考: https://github.com/riscv/riscv-gnu-toolchain/blob/master/README.md
离线
qemu-riscv64
qemu-system-riscv64请教下这两个命令有什么区别?
为什么楼主的程序用 qemu-riscv64, 而 xboot 的程序用 qemu-system-riscv64 ?lilo@ubuntu:/opt/# cat xboot/tools/qemu-system/linux/riscv64-virt-dbg.sh
#!/bin/sh
## The qemu's root directory.
export QEMU_DIR=$(cd `dirname $0` ; pwd)# Run qemu
exec qemu-system-riscv64 -M virt -m 512M -smp 2 -name "RiscV64 Virtual Machine" -S -gdb tcp::10000,ipv4 -show-cursor -rtc base=localtime -serial stdio -kernel ${QEMU_DIR}/../../../output/xboot
https://github.com/shihyu/Qemu/blob/master/uImage_qemu/QEMU%20and%20ARM%20Linux.md
qemu-arm和qemu-system-arm的區別:
qemu-arm是用戶模式的模擬器(更精確的表述應該是系統調用模擬器),而qemu-system-arm則是系統模擬器,它可以模擬出整個機器並運行操作系統
qemu-arm僅可用來運行二進制文件,因此你可以交叉編譯完例如hello world之類的程序然後交給qemu-arm來運行,簡單而高效。而qemu-system-arm則需要你把hello world程序下載到客戶機操作系統能訪問到的硬盤裡才能運行
离线