bochs是一個(gè)用來模擬IA32(x86)架構(gòu)的模擬器,包括x86的CPU路翻、通用輸入輸出I/O設(shè)備等钾挟。后續(xù)我們將使用bochs來運(yùn)行自己編寫的代碼首启,因此也需要用到bochs提供的debug功能,所以本文采用源碼編譯的方式來安裝驻龟。
源碼方式安裝
下載最新的源碼
下載路徑:https://sourceforge.net/projects/bochs/files/bochs/2.7/温眉,下載后的包名稱為bochs-2.7.tar.gz
。
編譯源碼&安裝
-
解壓下載的壓縮包
tar zcf bochs-2.7.tar.gz
解壓后會(huì)出現(xiàn)目錄
bochs-2.7
翁狐。 -
配置編譯選項(xiàng)
cd bochs-2.7
./configure --enable-debugger
打開bochs的debug功能类溢,這樣在運(yùn)行bochs時(shí)可以使用類似
Linux
下的gdb
功能進(jìn)行調(diào)試。 -
編譯并安裝
make
sudo make install
整個(gè)編譯過程大概需要十分鐘露懒,編譯完成后會(huì)生成
bochs
和bximage
兩個(gè)可執(zhí)行文件闯冷,bochs
就是模擬器本身二進(jìn)制文件,bximage
則用于創(chuàng)建各種虛擬鏡像(例如軟盤鏡像懈词、硬盤鏡像等)窃躲。默認(rèn)會(huì)將這兩個(gè)可執(zhí)行文件安裝到系統(tǒng)的/usr/local/bin
目錄下。
安裝完成后钦睡,在命令行輸入bochs就可以打開模擬器了蒂窒,此時(shí)是無法正常出現(xiàn)bochs的界面躁倒,因?yàn)樾枰峁゜ochs的配置文件,指定待模擬系統(tǒng)的一些配置洒琢,這個(gè)在后文會(huì)介紹如何使用bochs秧秉,此處不做深入探討。
輸入bochs后的界面:
========================================================================
Bochs x86 Emulator 2.7
Built from SVN snapshot on August 1, 2021
Timestamp: Sun Aug 1 10:07:00 CEST 2021
========================================================================
00000000000i[ ] BXSHARE not set. using compile time default '/usr/local/share/bochs'
------------------------------
Bochs Configuration: Main Menu
------------------------------
This is the Bochs Configuration Interface, where you can describe the
machine that you want to simulate. Bochs has already searched for a
configuration file (typically called bochsrc.txt) and loaded it if it
could be found. When you are satisfied with the configuration, go
ahead and start the simulation.
You can also start bochs with the -q option to skip these menus.
1. Restore factory default configuration
2. Read options from...
3. Edit options
4. Save options to...
5. Restore the Bochs state from...
6. Begin simulation
7. Quit now
Please choose one: [2]
問題及解決方案
一般問題會(huì)出現(xiàn)在編譯前的配置過程衰抑,多為本地環(huán)境檢測(cè)達(dá)不到要求象迎,可以嘗試打bochs-2.7``目錄下的
configure`文件,根據(jù)錯(cuò)誤提示分析下具體錯(cuò)誤出現(xiàn)的位置以及錯(cuò)誤出現(xiàn)的邏輯呛踊。多數(shù)情況下都是環(huán)境的配置不滿足要求(例如某些依賴的庫未安裝)砾淌,下面記錄的問題是本文安裝過程中碰到的。
-
運(yùn)行
./configure
時(shí)提示"ERROR: X windows gui was selected, but X windows libraries were not found."原因在錯(cuò)誤信息中已經(jīng)提示的很清楚谭网,因?yàn)槲覀冃枰褂胓ui界面汪厨,而本地環(huán)境沒有檢測(cè)到對(duì)應(yīng)的
X windows gui
庫,解決方案就是為本地環(huán)境安裝X windows gui
庫愉择,命令如下:sudo apt install xorg-dev
-
運(yùn)行
./configure
時(shí)提示"WARNING: The Bochs debugger gui cannot be compiled here, disabling it"錯(cuò)誤提示中并未明確能看到原因劫乱,只知道是對(duì)應(yīng)的gui庫沒有找到,通過提示信息找configure文件內(nèi)容锥涕,發(fā)現(xiàn)提示附近的代碼為:
ENH_DBG_OBJS="" if test "$gui_debugger" = 1; then if test "$bx_have_gtk_version" -ge 2; then ENH_DBG_OBJS="enh_dbg.o gtk_enh_dbg_osdep.o" $as_echo "#define BX_DEBUGGER_GUI 1" >>confdefs.h elif test "$DEFAULT_GUI" = win32 -o "$with_win32" = yes; then ENH_DBG_OBJS="enh_dbg.o win32_enh_dbg_osdep.o" $as_echo "#define BX_DEBUGGER_GUI 1" >>confdefs.h else { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: , disabling it" >&5 $as_echo "$as_me: WARNING: The Bochs debugger gui cannot be compiled here, disabling it" >&2;} $as_echo "#define BX_DEBUGGER_GUI 0" >>confdefs.h fi fi
可以進(jìn)一步去查看
gui_debugger
標(biāo)志和bx_have_gtk_version
標(biāo)志的賦值邏輯衷戈,此處不詳細(xì)贅述,最終結(jié)果為需要安裝gtk2.0和gtk3.0的開發(fā)庫层坠,命令如下:sudo apt install libgtk-3-dev
sudo apt install libgtk2.0-dev
附錄
bochs官方鏈接:https://bochs.sourceforge.io/
-
本文所使用的環(huán)境
軟件名稱 軟件版本 Linux操作系統(tǒng) Ubuntu 22.04 LTS(X64) gcc 11.4.0