$qemu-riscv64 -L /usr/riscv64-linux-gnu/ hello
hello
$
或者用 QEMU_LD_PREFIX 环境变量:
QEMU_LD_PREFIX=/usr/riscv64-linux-gnu/ qemu-riscv64 hello
按这个加上 LD_LIBRARY_PATH 没用?
$ LD_LIBRARY_PATH=/usr/riscv64-linux-gnu/ qemu-riscv64 hello
qemu-riscv64: Could not open '/lib/ld-linux-riscv64-lp64d.so.1': No such file or directory
$
$ LD_LIBRARY_PATH=/usr/riscv64-linux-gnu/lib/ qemu-riscv64 hello
qemu-riscv64: Could not open '/lib/ld-linux-riscv64-lp64d.so.1': No such file or directory
$
好像一定要用静态链接, 否则会这样:
$ riscv64-linux-gnu-gcc -o hello hello.c
$
$ qemu-riscv64 hello
qemu-riscv64: Could not open '/lib/ld-linux-riscv64-lp64d.so.1': No such file or directory
$
wget https://download.qemu.org/qemu-6.0.0.tar.xz
tar xvJf qemu-6.0.0.tar.xz
cd qemu-6.0.0
./configure
make
#
# You must pass CROSS_COMPILE and PLATFORM variable.
#
CROSS_COMPILE ?=arm-linux-gnueabihf-
PLATFORM ?=arm32-realview
----------------------------------------------------------
错误提示:
make all
Usage:
make [-AeEhiknpqrsStTuvVx] [-P#] [-f file] [macro[][+][:]=value ...] [target ...]
make: Error code 255, while making 'all'
11:05:56 Build Finished. 0 errors, 0 warnings. (took 158ms)
]]>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程序下載到客戶機操作系統能訪問到的硬盤裡才能運行
我新建的一个 test5.s 文件:
.global _start
_start:
addi a0, x0, 0x7FF ###这里立即数 用 0x000 - 0x7FF 都不会编译出错
j _start编译指令:
riscv64-unknown-elf-gcc -o test5 test5.s -nostdlib -g --entry _start
如果立即数改成 0x800 或者以上就会出错:
#riscv64-unknown-elf-gcc -o test5 test5.s -nostdlib -g --entry _start
test5.s: Assembler messages:
test5.s:4: Error: illegal operands `addi a0,x0,0x800'这是为什么呢?
在 RISCV手册里面,规定了 addi 指令的立即数是 12位有符号的, 所以表示范围是 -2048 - +2047(0x7FF)
所以明显你的 0x800 超过了立即数的范围.
0x800 及其之后已经是负数了.
看下手册, 我记得在 RISC-V指令集里面, 负数是补码形式存在了.
]]>.global _start
_start:
addi a0, x0, 0x7FF ###这里立即数 用 0x000 - 0x7FF 都不会编译出错
j _start
编译指令:
riscv64-unknown-elf-gcc -o test5 test5.s -nostdlib -g --entry _start
如果立即数改成 0x800 或者以上就会出错:
#riscv64-unknown-elf-gcc -o test5 test5.s -nostdlib -g --entry _start
test5.s: Assembler messages:
test5.s:4: Error: illegal operands `addi a0,x0,0x800'
这是为什么呢?
]]>请教下这两个命令有什么区别?
为什么楼主的程序用 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
需要先构建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
]]>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
]]>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>