《从0开始写一个微内核操作系统》0-环境准备

环境

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

Ninja构建

安装依赖

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

GN构建

安装依赖

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作为模拟器进行仿真调试

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

QEMU board

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进行定制
我们选择

  • CPU:cortex-a53
  • Memory:1G

默认uart = pl011

根据配置输出DTS信息

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 debug

启动gdb server

qemu-system-aarch64 -M virt -cpu cortex-a53 -m 1024 -nographic -kernel ./out/os.elf -S -s

启动gdb client

aarch64-none-elf-gdb --tui ./out/os.elf
target remote localhost:1234

常用GDB操作

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

VSCode + QEMU + GDB

launch.json
{
    // 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"
        }
    ]
}
tasks.json
{
    // 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调试
在这里插入图片描述

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值