Ubuntu 18.04.6 LTS
我们选择GCC的裸机版本(Arm GNU Toolchain Downloads – Arm Developer)
x86_64 Linux hosted cross toolchains --> AArch64 bare-metal target (aarch64-none-elf)
编译工具:Ninja
构建工具:GN
安装依赖
sudo apt install re2c
re2c --version
下载Ninja
git clone https://github.com/ninja-build/ninja.git
编译安装
./configure.py --bootstrap
sudo cp ninja /usr/bin
ninja --version
安装依赖
sudo apt-get install clang-7
修改软链接
cd /usr/bin
sudo ln -s clang-7 clang
sudo ln -s clang++-7 clang++
sudo ln -s clang-cpp-7 clang-cpp
clang++ --version
下载GN
git clone https://github.com/timniederhausen/gn.git
编译安装
./build/gen.py
ninja -C out
sudo cp ./out/gn /usr/bin
gn --version
我们选择QEMU作为模拟器进行仿真调试
# 7.0
wget https://download.qemu.org/qemu-7.0.0.tar.xz
sudo apt install pkg-config
sudo apt install libglib2.0-dev
sudo apt install libpixman-1-dev
sudo apt install bison flex
sudo ./configure --target-list=aarch64-softmmu --enable-kvm
#sudo ./configure --target-list=arm-softmmu --enable-kvm
sudo make -j8
sudo make install
qemu-system-aarch64 --version
#qemu-system-arm --version
board:virt(‘virt’ generic virtual platform (virt) — QEMU 7.1.50 documentation)
默认virt = virt-7.0
默认gic-version = gicv3(vir >= virt-2.7)
可根据自己需求进行cpu/memory/device进行定制
我们选择
默认uart = pl011
qemu-system-aarch64 -cpu cortex-a53 -m 512 -smp 4 -M virt,gic-version=3,dumpdtb=dump.dtb
dtc -o dump.dts -O dts -I dtb dump.dtb
qemu-system-aarch64 -M virt -cpu cortex-a53 -m 1024 -nographic -kernel ./out/os.elf -S -s
aarch64-none-elf-gdb --tui ./out/os.elf
target remote localhost:1234
break 16 <----------- 设置断点,在源程序第16行处
break func <----------- 设置断点,在函数func()入口处
info break <----------- 查看断点信息。
r <----------- 运行程序,run命令简写
n <----------- 单条语句执行,next命令简写
c <----------- 继续运行程序,continue命令简写
p i <----------- 打印变量i的值,print命令简写
bt <----------- 查看函数堆栈
q <----------- 退出gdb
break *address <----------- 在程序运行的内存地址处停住
delete n <----------- 清除n号断点
x/<n/f/u> <addr> <----------- 查看内存
eg: x/100uh 0x54320:从0x54320读取内容,h双字节为一个单位,100表示3个单位,u
ctrl+c <----------- 暂停
si/ni <----------- 单步运行
info registers/b <----------- 查看当前寄存器和断点
display /20i $pc <----------- 查看当前执行及后20行汇编指令
layout split
layout regs
layout asm
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "kernel qemu debug",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/out/os.elf",
"cwd": "${workspaceFolder}",
"MIMode": "gdb",
"miDebuggerPath":"aarch64-none-elf-gdb",
"miDebuggerServerAddress": "localhost:1234",
"preLaunchTask": "qemu"
}
]
}
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "qemu",
"type": "shell",
"command": "qemu-system-aarch64 -M virt -cpu cortex-a53 -m 1024 -nographic -kernel ${workspaceFolder}/out/os.elf -S -s",
"presentation": {
"echo": true,
"clear": true,
"group": "qemu"
},
"isBackground": true,
"problemMatcher": [],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
点击左上角的运行(F5)即可在VSCODE中进行GDB调试