QEMU-v8.2.4源碼中文注釋與架構講解
文檔會不定期更新
注釋作者 | 將狼才鯨 |
---|---|
創建日期 | 2025-05-30 |
更新日期 | 2025-06-02 |
- CSDN閱讀地址:QEMU源碼中文注釋與架構講解
- Gitee源碼倉庫地址:才鯨嵌入式/qemu
一、前言
- 其它參考教程的網址:
- QEMU 源碼目錄簡介:部分目錄介紹,函數入口,主循環
- qemu基本架構:架構
- qemu 學習(一)————qemu整體流程解讀:架構,重要的源文件,翻譯,反匯編,移植,大小端
- 共6篇文章
- qemu學習(四)————tcg操作碼 分析
- QEMU虛擬機關鍵源代碼學習:指令翻譯過程,尋址轉換,數據結構
- QEMU源碼分析系列(一):系列文章:QEMU簡介,翻譯過程,內存模型
- qemu源碼分析系列(二)
- QEMU源碼分析系列(三)
- qemu源碼分析之五-- TCG動態翻譯技術
- qemu 內存模型(內存仿真概念)
- qemu用戶態仿真代碼分析
- qemu中ELF文件的加載
- qemu指令翻譯過程(1)-- ADD指令
- qemu源碼分析之Makefile
- Qemu快照(snapshot)機制原理及關鍵技術理解
- QEMU虛擬機(一)、源碼分析概論:系列文章:QEMU簡述,KVM虛擬化
- Linux虛擬化KVM-Qemu分析(一)虛擬化框架綜述
- 共10篇
- Linux虛擬化KVM-Qemu分析(八)之virtio初探
- KVM學習筆記:該教程里內容很多
- Qemu架構解析(二):流程簡介
- Qemu源碼分析(1)—Apple的學習筆記:系列教程
- 大總結:qemu第二輪源碼學習–Apple的學習筆記:文章目錄
- 共11篇
- Qemu源碼分析(11)—Apple的學習筆記
- qemu源碼解析一:簡介,初始化過程
- qemu源碼解析二
- qemu源碼分析(一)-- QOM類創建流程:系列教程:初始化,函數調用,終端,寄存器,外設,參數,設備,編譯,面向對象QOM
- 共7篇
- qemu源碼分析(七)-- 中斷處理之PPC系列
- QEMU 3.1.0 源碼學習:遷移,重要的源文件
- 《QEMU/KVM源碼分析與應用》讀書筆記1 —— 第1章 QEMU與KVM概述:要錢!系列文章,共174篇;簡介,安裝,參數,QOM,機器,外設,內存、CPU、設備虛擬化。
- qemu學習筆記:QOM:抽象層,面向對象
- 菜雞讀QEMU源碼:架構,調用過程
二、整體介紹
1、源碼文件夾結構與簡述
jim@virtual-pc:~/qemu$ tree -a -L 1
.
├── accel # 硬件加速器、純軟件翻譯:kvm、xen、tcg
├── audio # 音頻設備模擬
├── authz # 授權框架,限制虛擬機對設備、API 或特定操作的訪問權限
├── backends # 后端實現:主機內存管理、TPM 后端
├── BAK_README.rst # 原本倉庫的readme文件
├── block # 塊設備:導出、IO、任務管理
├── block.c
├── blockdev.c
├── blockdev-nbd.c
├── blockjob.c
├── bsd-user # BSD 用戶模式模擬
├── chardev # 字符設備模擬
├── common-user # 用戶模式公共代碼
├── configs # 編譯相關
├── configure # 配置腳本
├── contrib # 社區貢獻的輔助工具、腳本或第三方庫
├── COPYING # 開源信息
├── COPYING.LIB # 開源信息相關
├── cpu-common.c # 核心組件之一,主要負責 CPU 虛擬化的通用邏輯和基礎功能實現
├── cpu-target.c # 針對特定目標架構的 CPU 模型實現代碼
├── crypto # 加解密,數字簽名
├── .dir-locals.el # Emacs 編輯器 的本地目錄變量配置文件
├── disas # 反匯編器支持
├── docs # 技術文檔,英文的,而且對新手沒什么用
├── docs_中文 # 字節寫的一些中文文檔
├── dump # 系統崩潰情況下調試用
├── ebpf # 增強 QEMU 的調試、性能分析或安全監控能力
├── .editorconfig # 配置文件,主要用于統一代碼風格和編輯器設置
├── event-loop-base.c # 實現事件循環基礎框架的核心文件
├── .exrc # Vi/Vim 編輯器的配置文件
├── fpu # 浮點運算庫
├── fsdev # 文件系統設備
├── .gdbinit # 調試器相關
├── gdbstub # GDB 調試支持
├── gdb-xml # # 調試器相關
├── .git # git代碼管理倉庫
├── .gitattributes # git代碼管理對比工具配置
├── .git-blame-ignore-revs # git代碼管理相關
├── gitdm.config # git代碼管理相關
├── .github # git代碼管理服務器相關
├── .gitignore # git代碼管理忽略的文件信息配置
├── .gitlab # git代碼管理服務器相關
├── .gitlab-ci.d # git代碼管理服務器自動測試相關
├── .gitlab-ci.yml # git代碼管理服務器自動測試相關
├── .gitmodules # git代碼管理相關
├── .gitpublish # git代碼管理相關
├── hmp-commands.hx # 定義HMP命令的源碼。HMP是一種交互式監控接口
├── hmp-commands-info.hx # 交互式監控接口相關
├── host # 臨時構建目錄
├── hw # 所有支持的硬件設備,硬件設備模擬的核心目錄,按架構與設備類型分類
├── include # 公用頭文件:硬件、核心、C標準庫
├── io # IO通道實現
├── iothread.c # IO線程的核心實現
├── job.c # QEMU任務的核心實現
├── job-qmp.c # 異步任務管理的QMP接口
├── Kconfig # 源碼編譯相關
├── Kconfig.host # 源碼編譯相關
├── libdecnumber # 十進制浮點數運算庫
├── LICENSE # 開源信息相關
├── linux-headers # Linux 內核相關的頭文件
├── linux-user # Linux 用戶模式模擬
├── .mailmap # git版本管理相關
├── MAINTAINERS # 記錄代碼維護者信息
├── Makefile # 編譯參數相關,頂層構建文件
├── memory_ldst.c.inc # 內存訪問操作的實現
├── meson.build # Meson構建系統的核心配置文件
├── meson_options.txt # 系統構建相關
├── migration # 虛擬機遷移相關
├── module-common.c # 模塊化系統的核心實現
├── monitor # QEMU監控器
├── nbd # 網絡塊設備支持
├── net # 網絡設備模擬
├── os-posix.c # POSIX 操作系統兼容層的實現
├── os-win32.c # 專門為 Windows 平臺實現的輔助功能模塊
├── page-vary-common.c # 動態頁面大小處理 相關的核心文件
├── page-vary-target.c # 動態頁面大小處理相關
├── .patchew.yml # 與 Patchew 系統集成的配置文件
├── pc-bios # BIOS和固件鏡像
├── plugins # 插件支持
├── po # 國際化i18n支持
├── python # Python 腳本和工具
├── pythondeps.toml # Python相關
├── qapi # QAPI 代碼生成器
├── qemu-bridge-helper.c # 實現用戶態網絡橋接助手的功能
├── qemu-edid.c
├── qemu-img.c
├── qemu-img-cmds.hx
├── qemu-io.c
├── qemu-io-cmds.c
├── qemu-keymap.c
├── qemu-nbd.c
├── qemu.nsi
├── qemu-options.hx
├── qemu.sasl
├── qga # 宿主機-虛擬機通信
├── qobject # 基礎的面向對象組件
├── qom # QEMU 對象模型,用C語言實現面向對象
├── readme.md # 本倉庫新增的主頁說明文件
├── .readthedocs.yml # 配置RTD在線文檔托管服務的配置文件
├── replay # 執行記錄和回放
├── replication.c # 塊設備復制功能的實現核心
├── roms # ROM 鏡像
├── scripts # 源碼編譯相關,構建和維護腳本
├── scsi # SCSI磁盤等設備模擬
├── semihosting # 半主機機制
├── stats # 代碼統計和性能分析相關工具
├── storage-daemon # 存儲守護進程
├── stubs # 樁函數
├── subprojects # 依賴的子項目
├── system # 系統級虛擬化(全系統模擬),也是源碼主入口(main函數所在位置)
├── target # QEMU目前所支持guset端的處理器架構,將該guest架構的指令翻譯成TCG OP代碼,里面的目錄占源碼總目的很大一部分
├── tcg # 動態翻譯工具tcg的源碼部分,主要是將TCG OP轉化為host binary的部分;也就是俗稱的軟件加速,而我們一般裝Ubuntu這種大系統時需要選KVM、WHPX等硬件加速
├── tests # 測試代碼
├── tools # 輔助工具
├── trace # 跟蹤支持
├── trace-events # 跟蹤相關
├── .travis.yml # 配置 Travis CI(持續集成服務)的配置文件
├── ui # 用戶界面 (GTK, SDL, Cocoa 等)
├── util # 實用工具函數
├── VERSION # 開源信息相關
├── version.rc # 開源信息相關
└── .vscode # 編輯器相關60 directories, 61 files
jim@virtual-pc:~/qemu$
2、源碼入口
-
第一行執行的代碼,也就是main函數所在的位置
-
qemu-system-xxx(如-arm、-x86_64)應用程序執行的第一行代碼在源碼中 system/main.c 里的main()函數位置
- 對于系統模式,main() 函數會初始化虛擬硬件,然后開始執行虛擬 CPU
- 虛擬 CPU 初始化:target/i386/cpu.c(x86 為例)
-
所有包含了main.c文件 + main()函數的位置:
jim@virtual-pc:~/qemu$ find . -name main.c
./contrib/ivshmem-client/main.c # contrib是第三方庫所在的文件,不算
./contrib/elf2dmp/main.c
./contrib/vhost-user-input/main.c
./contrib/rdmacm-mux/main.c
./contrib/ivshmem-server/main.c
./system/main.c # QEMU 系統模式如qemu-system-arm程序的主入口點,負責初始化虛擬機的核心邏輯。它是模擬完整物理機器(如x86、ARM)時的關鍵組成部分。
./pc-bios/vof/main.c # PowerPC(ppc64)架構相關
./pc-bios/s390-ccw/main.c
./linux-user/main.c # 用戶模式的啟動入口。當運行命令如qemu-<arch> ./binary 時,程序從這里開始初始化,加載并執行目標架構的二進制文件(例如在x86主機上運行ARM程序)
./qga/main.c # 實現客戶機代理功能,即用于與宿主機端的QEMU監控程序進行通信
./bsd-user/main.c # BSD用戶模式模擬的入口點,針對的是BSD類操作系統(如FreeBSD、NetBSD、OpenBSD等)
jim@virtual-pc:~/qemu$
-
在 system/main.c 中,main() 函數是一個簡單的封裝,調用 qemu_main() 函數,而后者負責實際的循環工作
- qemu_init():負責全局初始化(如設備注冊、內存管理、加速器配置等)。
- qemu_main_loop():進入主事件循環,處理虛擬機運行邏輯。
- qemu_cleanup():在退出時執行清理工作。
- 解析命令行參數(如 -machine、-kernel 等),調用初始化函數
-
system/vl.c 承擔核心工作
三、編譯與使用
1、源碼編譯
-
參考網址:
- ubuntu20.04源碼編譯安裝qemu(qemu8.2)
-
本機系統:
jim@virtual-pc:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04.6 LTS
Release: 20.04
Codename: focal
jim@virtual-pc:~$
- 本機源碼:
- 截止到2025-06-01時的穩定版分支v8.2.4的源碼
- 如果你不介意版本是否穩定,也可以直接在v9.0.0 tag的基礎上進行修改;
- QEMU官網雖然已經能下載v10.0.2和v9.2.4的軟件了,但是源碼倉庫里還沒有這2個標簽,并且官網源碼的最后上傳時間是一年前。
- 截止到2025-06-01時的穩定版分支v8.2.4的源碼
2024-05-13 08:29 +0300 Michael Tokarev o─{origin/stable-8.2} {origin/staging-8.2} <v8.2.4> Update version for 8.2.4 release
-
編譯過程:
-
1、提前修改編譯過程中需要聯網拉取的gitlab.com網站中的子git倉庫的國內Gitee源(本倉庫內我已修改好了,請在本文章最上方的Gitee源碼鏈接下拉取改好的QEMU倉庫)
- 如果你能登上gitlab.com,則請忽略此步驟;
- 如果你沒使用梯子,則編譯配置時需要拉取源碼,然后因為gitlab網站被墻導致失敗;
- 具體需要的子倉庫是:gitlab.com/qemu-project/seabios.git SLOF.git ipxe.git openbios.git qemu-palcode.git u-boot.git skiboot.git QemuMacDrivers.git seabios-hppa.git u-boot-sam460ex.git edk2.git opensbi.git qboot.git vbootrom.git libvirt-ci.git
- 自行修改的方法1:
- 把QEMU倉庫里的所有 https://gitlab.com/qemu-project/ 字符串替換為 https://gitee.com/tinylab/qemu-
- 自行修改的方法2:
- 主要是.gitmodules文件中、subprojects/ 文件夾下、tests/文件夾下的非gitlab.com/qemu-project/qemu.git 部分不替換會出錯(編譯時qemu.git源碼我們肯定已經拉取了,是其它倉庫造成的編譯時預配置不通過),子模塊拉不下來;
- 將 .gitmodules 文件中所有 gitlab.com/qemu-project/ 替換成 gitee.com/tinylab/qemu-
- 將 subprojects\ 文件夾下所有 .wrap 文件中的 gitlab.com/qemu-project/ 替換成 gitee.com/tinylab/qemu-
- 具體包括:
- subprojects\keycodemapdb.wrap
- subprojects\berkeley-softfloat-3.wrap
- subprojects\dtc.wrap
- subprojects\libvfio-user.wrap
- 將 tests\ 文件夾下所有 .wrap 文件中的 gitlab.com/qemu-project/ 替換成 gitee.com/tinylab/qemu-
- 具體包括:
- tests\avocado\acpi-bits.py
- tests\qtest\fuzz-lsi53c895a-test.c
- tests\qtest\fuzz-megasas-test.c
- tests\qtest\fuzz-sdcard-test.c
- tests\qtest\intel-hda-test.c
- tests\tcg\aarch64\mte-7.c
- tests\tcg\aarch64\test-2150.c
- tests\tcg\aarch64\test-2248.c
- 如果上述國內鏡像倉庫也失效的話,則在Gitee網站搜索 qemu-project ,再換一個好心人提供的國內源
-
你也可以試著先把全部代碼拉下來,或者找到完整的國內鏡像源,預先從外網拉取全量代碼的步驟如下:
- git clone https://gitlab.com/qemu-project/qemu.git
- cd qemu
- git submodule init
- git submodule update --recursive
-
2、因少數非關鍵國內源子倉庫版本不匹配,編譯不通過,需要修改 tests\fp\meson.build 文件
- (本倉庫內我已修改好了,請在本文章最上方的Gitee源碼鏈接下拉取改好的QEMU倉庫)
- 如果你能登上gitlab.com,則請忽略此步驟;
- 國內鏡像子倉庫里源碼版本的同步時間不是我當前時間,和qemu-project中的實際倉庫的內容不同步,我這里遇到的是berkeley-testfloat-3.git編譯報錯
- 將 tests\fp\meson.build 文件中第32行到35行、第47到52行、第108到源碼最后的143行前面加上#井號來屏蔽腳本
- 這部分內容本來也是測試用例,刪掉不影響實際使用
-
3、更新軟件包索引
sudo apt update
-
4、安裝編譯時依賴的軟件和庫(必須要先裝)
sudo apt install gcc make python3-venv python3-pip ninja-build libglib2.0-dev flex bison libcapstone-dev libfdt-dev device-tree-compiler
-
5、使用python環境安裝軟件包
pip3 install Sphinx sphinx_rtd_theme
-
6、進行編譯前的配置:
cd ~/qemu
# 進入源碼目錄mkdir build
cd build
../configure
# 配置為全部目標進行編譯- 以下是執行過程:
jim@virtual-pc:~$ cd ~/qemu
jim@virtual-pc:~/qemu$ mkdir build
jim@virtual-pc:~/qemu$ cd build
jim@virtual-pc:~/qemu/build$ ../configure
python determined to be '/usr/bin/python3'
python version: Python 3.8.10
mkvenv: Creating non-isolated virtual environment at 'pyvenv'
mkvenv: checking for tomli>=1.2.0
mkvenv: installing tomli>=1.2.0
mkvenv: checking for meson>=0.63.0
mkvenv: installing meson==1.2.3
mkvenv: checking for sphinx>=1.6
mkvenv: checking for sphinx_rtd_theme>=0.5
The Meson build system
……Subprojectsberkeley-softfloat-3 : YESkeycodemapdb : YESlibvduse : YESlibvhost-user : YESUser defined optionsNative files : config-meson.crossdocs : enabledplugins : trueFound ninja-1.10.0 at /usr/bin/ninja
Running postconf script '/home/jim/qemu/build/pyvenv/bin/python3 /home/jim/qemu/scripts/symlink-install-tree.py'
jim@virtual-pc:~/qemu/build$
-
因為我只需要32位ARM平臺的工具,所以我實際使用的命令是:
../configure --target-list=arm-softmmu,arm-linux-user
-
7、編譯:
make -j4
# 使用4進程編譯;你的電腦是幾核就配成幾,也可以多配
jim@virtual-pc:~/qemu/build$ make -j4
[1/52] Generating tests/include/QAPI test (include) with a custom command
[2/20] Generating qemu-version.h with a custom command (wrapped by meson to capture output)
jim@virtual-pc:~/qemu/build$
- 8、將編譯好的 qemu-system-arm 等應用程序安裝到Ubuntu系統內:
sudo make install
jim@virtual-pc:~/qemu/build$ sudo make install
[1/20] Generating qemu-version.h with a custom command (wrapped by meson to capture output)
[1/2] Installing files.
Installing subdir /home/jim/qemu/build/docs/manual to /usr/local/share/doc/qemu
……
Installing /home/jim/qemu/pc-bios/keymaps/sv to /usr/local/share/qemu/keymaps
jim@virtual-pc:~/qemu/build$
- 9、測試程序的使用(查看版本號):
qemu-system-arm --version
jim@virtual-pc:~/qemu/build$ qemu-system-arm --version
QEMU emulator version 8.2.4 (v8.2.4-9-g953cc60a63-dirty)
Copyright (c) 2003-2023 Fabrice Bellard and the QEMU Project developers
jim@virtual-pc:~/qemu/build$
2、使用1:QEMU安裝并運行虛擬機
- 步驟詳見:
- Windows10下使用QEMU安裝Ubuntu20.04虛擬機,并啟用硬件加速
3、使用2:直接運行目標平臺程序
-
我編譯生成的是32位ARM平臺的QEMU,所以我不能直接在Ubuntu上使用GCC編譯程序后再在QEMU中運行運行,而需要使用ARM交叉編譯工具編完后再用qemu-system-arm來運行;
-
ARM交叉編譯工具介紹:
交叉編譯工具名 | 目的 |
---|---|
arm-none-eabi-gcc | 供裸機如Cortex-M3板子使用,不能使用fork()等系統類函數,不能編Linux應用 |
arm-linux-gnueabi-gcc | 用于編譯u-boot、Linux內核、linux應用,支持armel軟浮點,32位 |
arm-linux-gnueabihf-gcc | 支持armhf硬浮點,64位 |
arm-eabi-gcc | Android ARM 編譯器 |
armcc | 供Keil使用,編譯裸機程序,不能編譯Linux應用 |
arm-none-uclinuxeabi-gcc | 用于其它系統:uCLinux |
arm-none-symbianelf-gcc | 用于其它系統:symbian |
帶芯片廠商名字或由芯片廠商單獨提供 | 芯片原廠基于上述源碼定制的交叉編譯工具 |
-
1)安裝32位ARM交叉編譯工具:
sudo apt install gcc-arm-linux-gnueabi
-
2)查看安裝結果
arm-linux-gnueabi-gcc --version
jim@virtual-pc:~/qemu$ arm-linux-gnueabi-gcc --version
arm-linux-gnueabi-gcc (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.jim@virtual-pc:~/qemu$
-
3)編譯要測試的程序
cd ~/qemu
# 進入源碼目錄mkdir demo
cd demo
touch main.c
# 創建源碼文件gedit main.c
-
main.c文件中加入內容:
#include <stdio.h>int main()
{printf("Hello World!\n");fflush(stdout);while(1);return 0;
}
- 繼續:
arm-linux-gnueabi-gcc -o hello main.c -static
# 編譯生成hello程序(必須使用靜態庫)file hello
# 查看架構是否正確jim@virtual-pc:~/qemu/demo$ file hello
hello: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux.so.3, BuildID[sha1]=e02cd9a7928171b8c7631f7ef83182807a45ccf4, for GNU/Linux 3.2.0, not stripped
qemu-arm hello
# 使用qemu運行程序jim@virtual-pc:~/qemu/demo$ qemu-arm hello
Hello World!
- 不能使用運行操作系統鏡像的qemu-system-arm程序:
jim@virtual-pc:~/qemu/demo$ qemu-system-arm -machine raspi2b hello
WARNING: Image format was not specified for 'hello' and probing guessed raw.Automatically detecting the format is dangerous for raw images, write operations on block 0 will be restricted.Specify the 'raw' format explicitly to remove the restrictions.
qemu-system-arm: Invalid SD card size: 509 KiB
SD card size has to be a power of 2, e.g. 512 KiB.
You can resize disk images with 'qemu-img resize <imagefile> <new-size>'
(note that this will lose data if you make the image smaller than it currently is).
4、修改源碼,并查看是否生效
- 1)在system/main.c文件的main()函數中加入一行:
printf("(build time: %s %s, for system)main entry: file: %s, line: %d\n", __DATE__, __TIME__, __FILE__, __LINE__);
- 2)進入qemu/build目錄執行make命令
jim@virtual-pc:~/qemu/build$ make
/home/jim/qemu/build/pyvenv/bin/meson introspect --targets --tests --benchmarks | /home/jim/qemu/build/pyvenv/bin/python3 -B scripts/mtest2make.py > Makefile.mtest
[1/53] Generating qemu-version.h with a custom command (wrapped by meson to capture output)
[2/50] Compiling C object qemu-system-arm.p/system_main.c.o
[3/50] Linking target qemu-system-arm
[4/50] Compiling C object libqemu-arm-linux-user.fa.p/linux-user_main.c.o
[5/50] Linking target qemu-arm
[6/50] Compiling C object qga/qemu-ga.p/main.c.o
[7/50] Linking target qga/qemu-ga
[8/50] Compiling C object qemu-img.p/qemu-img.c.o
[9/50] Linking target qemu-img
[10/50] Compiling C object qemu-io.p/qemu-io.c.o
[11/50] Linking target qemu-io
[12/50] Compiling C object qemu-nbd.p/qemu-nbd.c.o
[13/50] Linking target qemu-nbd
[14/50] Compiling C object storage-daemon/qemu-storage-daemon.p/qemu-storage-daemon.c.o
[15/50] Linking target storage-daemon/qemu-storage-daemon
[16/50] Compiling C object qemu-pr-helper.p/scsi_qemu-pr-helper.c.o
[17/50] Linking target qemu-pr-helper
[18/50] Generating tests/include/QAPI test (include) with a custom command
jim@virtual-pc:~/qemu/build$jim@virtual-pc:~/qemu/build$ find . -name qemu-system-arm
./arm-softmmu/qemu-system-arm
./qemu-system-arm
./qemu-bundle/usr/local/bin/qemu-system-arm
jim@virtual-pc:~/qemu/build$ ls ./arm-softmmu/qemu-system-arm -l
lrwxrwxrwx 1 jim jim 18 6月 1 20:16 ./arm-softmmu/qemu-system-arm -> ../qemu-system-arm
jim@virtual-pc:~/qemu/build$ ls ./qemu-bundle/usr/local/bin/qemu-system-arm -l
lrwxrwxrwx 1 jim jim 36 6月 1 00:16 ./qemu-bundle/usr/local/bin/qemu-system-arm -> /home/jim/qemu/build/qemu-system-arm
jim@virtual-pc:~/qemu/build$ ls -l ./qemu-system-arm
-rwxrwxr-x 1 jim jim 115438744 6月 2 13:21 ./qemu-system-arm
jim@virtual-pc:~/qemu/build$
- 3)運行你剛剛生成的
./qemu-system-arm --version
查看效果- 這一行命令的執行需要在qemu/build目錄下
- 這一行內容的實際信息也能防止你改完源碼后沒運行到剛剛編譯的程序,實際運行了已安裝在系統中的舊程序;
jim@virtual-pc:~/qemu/build$ ./qemu-system-arm --version
(Jun 2 2025 13:21:18)main entry: file: ../system/main.c, line: 53
QEMU emulator version 8.2.4 (v8.2.4-13-g8fdc46628f-dirty)
Copyright (c) 2003-2023 Fabrice Bellard and the QEMU Project developers
jim@virtual-pc:~/qemu/build$
- 4)或者修改linux-user/main.c文件,之后用qemu-arm --version來驗證是否生效
jim@virtual-pc:~/qemu/build$ make
[1/19] Generating qemu-version.h with a custom command (wrapped by meson to capture output)
[2/3] Compiling C object libqemu-arm-linux-user.fa.p/linux-user_main.c.o
[3/3] Linking target qemu-arm
jim@virtual-pc:~/qemu/build$ ls -l qemu-arm
-rwxrwxr-x 1 jim jim 25443984 6月 2 13:41 qemu-arm
jim@virtual-pc:~/qemu/build$ ./qemu-arm --version
(build time: Jun 2 2025 13:41:49, for user bin)main entry: file: ../linux-user/main.c, line: 689
qemu-arm version 8.2.4 (v8.2.4-13-g8fdc46628f-dirty)
Copyright (c) 2003-2023 Fabrice Bellard and the QEMU Project developers
jim@virtual-pc:~/qemu/build$