使用rust写的hypervisor, 主要面向mission-critical的设备和系统,参考了JailHouse、RVM等项目。
[build]
target = "aarch64-unknown-none"
[target.aarch64-unknown-linux-gnu]
linker = "aarch64-linux-gnu-gcc"
rustflags = [
"-C", "link-arg=-nostartfiles -Tlinker.ld",
]
[target.aarch64-unknown-none]
linker = "aarch64-none-elf-gcc"
其中需要安装linker:aarch64-none-elf-
地址:https://developer.arm.com/-/media/Files/downloads/gnu-a/10.3-2021.07/binrel/gcc-arm-10.3-2021.07-x86_64-aarch64-none-elf.tar.xz?rev=9d9808a2d2194b1283d6a74b40d46ada&hash=4E429A41C958483C9DB8ED84B051D010F86BA624
安装rust toolchain:rustup install nightly && rustup default nightly && rustup target add aarch64-unknown-none (optional, we use json config)
apt install gdb-multiarch
make
make start
OR
qemu-system-aarch64 \
-M virt \
-m 1024M \
-cpu cortex-a53 \
-nographic \
-kernel target/aarch64-unknown-linux-gnu/debug/armv8-baremetal-demo-rust
qemu-system-aarch64 \
-M virt \
-m 1024M \
-cpu cortex-a53 \
-nographic \
-machine virtualization=on \
#-machine secure=on \
-kernel target/aarch64-unknown-linux-gnu/debug/armv8-baremetal-demo-rust \
-S -s
然后使用
gdb-multiarch target/aarch64-unknown-linux-gnu/debug/armv8-baremetal-demo-rust
进入gdb 输入:target remote :1234
即开始调试
PS: -machine virtualization=on开启虚拟化,则启用EL2,-machine secure=on,则启用EL3。我们只需要从EL2启动即可。 然后使用aarch64-linux-gnu-gdb -x debug.gdb。qemu默认从EL1启动virt
参考:
- https://stackoverflow.com/questions/42824706/qemu-system-aarch64-entering-el1-when-emulating-a53-power-up
- https://stackoverflow.com/questions/31787617/what-is-the-current-execution-mode-exception-level-etc
- https://github.com/cirosantilli/linux-kernel-module-cheat/tree/35684b1b7e0a04a68987056cb15abd97e3d2f0cc#arm-exception-level
- 下载并制作ubuntu镜像,在qemu中启动
make image
- 在qemu中启动制作好的虚拟机镜像
make qemu
- 下载gdb source: https://ftp.gnu.org/gnu/gdb/gdb-13.1.tar.gz
- tar -xzvf gdb-13.1.tar.gz
- mkdir build
- cd $_
- ../configure --prefix=$PWD --target=aarch64-linux-gnu PS: host填写自己电脑里交叉编译器的前缀,然后configure会自动寻找该前缀的编译器
- make -j$(nproc) [CFALGS=-static CXXFLAGS=-static]
PS: --target指定要调试的程序的架构 --host指定运行gdb程序的架构
参考: http://ruer.fun/2021/04/20/GDB-%E7%BC%96%E8%AF%91%E6%96%B9%E6%B3%95-2021/
- download qemu7.2.source
- tar 解压
- mkdir build %% cd build
- ../qemu-7.2.0/configure --enable-kvm --enable-slirp --enable-debug --target-list=aarch64-softmmu,x86_64-softmmu
- make -j2