Skip to content

Instantly share code, notes, and snippets.

@fairfieldt
Last active June 3, 2021 23:04
Show Gist options
  • Save fairfieldt/d24239e6f509454b60206b7b27b9c5f4 to your computer and use it in GitHub Desktop.
Save fairfieldt/d24239e6f509454b60206b7b27b9c5f4 to your computer and use it in GitHub Desktop.
slow vs fast qemu runs

Running riscv64 on qemu with the virt machine.

kernel is a simple elf program that expects to start in supervisor mode, sets up pages tables and some interrupt handlers and then runs a "program" in user mode.

When I run it with opensbi as the bios (fw_jump.efl), which jumps to the address 0x80200000, the code runs as expected. The code is put at that address with -device loader

When I run it with opensbi jumping to u-boot, which then loads the same code (packaged into a u-boot image with the script shown), like bootm 0x9000000 - 0x82200000 it still runs as expected but it is much much slower.

#!/usr/bin/env bash
command="/usr/bin/qemu-system-riscv64 \
-machine virt \
-cpu rv64
-smp 1 \
-m 2G \
-nographic \
-display none \
-serial mon:stdio \
-device loader,file=./target/riscv64gc-unknown-none-elf/debug/kernel \
-bios bin/fw_jump.elf \
"
if [[ $1 == "-d" ]]; then
command="$command -S -gdb tcp::26000"
fi
$command
#!/usr/bin/env bash
SCRIPT_DIR=`dirname $(readlink -f $0)`
ROOT_DIR="$SCRIPT_DIR/..
riscv64-buildroot-linux-gnu-objcopy -R -S -O binary $ROOT_DIR/target/riscv64gc-unknown-none-elf/debug/kernel $ROOT_DIR/target/riscv64gc-unknown-none-elf/debug/kernel.bin
/home/fairfieldt/dev/riscv-dev/u-boot/tools/mkimage -n "kernel image" \
-A riscv \
-O linux \
-C none \
-T kernel \
-a 0x80200000 \
-e 0x80200000 \
-d $ROOT_DIR/target/riscv64gc-unknown-none-elf/debug/kernel.bin \
-n posimg \
build/posimg
#!/usr/bin/env bash
command="/usr/bin/qemu-system-riscv64 \
-machine virt \
-cpu rv64 \
-smp 1 \
-m 2G \
-nographic \
-display none \
-serial mon:stdio \
-device loader,file=bin/u-boot.bin,force-raw=on,addr=0x8020000 \
-bios bin/fw_jump.elf \
-device loader,file=./build/posimg,force-raw=on,addr=0x90000000 \
"
if [[ $1 == "-d" ]]; then
command="$command -S -gdb tcp::26000"
fi
$command
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment