前言:本機環境ubuntu 14.04 bochs 2.4.5
一.下載
官網 http://bochs.sourceforge.net/
二.安裝
1.將下載好的壓縮包解壓並進入該目錄
tar vxzf bochs-2.4..tar.gz
cd bochs-2.4.
2.安裝編譯程式依賴的包
sudo apt-get install build-essential
3.檢測環境,開啟除錯功能的開關
./configure --enable-debugger --enable-disasm
(1)如出現 ERROR: X windows gui was selected, but X windows libraries were not found. 輸入
sudo apt-get install xorg-dev
(2)如出現 ERROR: pkg-config was not found, or unable to access the gtk+-2.0 package. 輸入
sudo apt-get install libgtk2.-dev
如有ERROR,依賴包安裝好後,需重新configure
(注*:我下載bochs-2.3.5時出現錯誤1,安裝xorg-dev也無法解決,不知什麼原因。還請前輩們多多指教!於是換成了bochs-2.4.5,親測可用)
4.編譯
make
(1)如出現 Error: collect2: error: ld returned 1 exit status
make: *** [bochs] Error 1
編輯boches-2.4.5/Makefile.in檔案,找到 LIBS = ... 一行,在行尾加上 -lpthread,儲存
重新configure之後,再重新make,成功
5.安裝
sudo make install
三.配置
如書中11頁所言,安裝好bochs後需要自己編寫配置檔案。儲存路徑卻並未明確指出,但原書中後面有提示:“如果你輸入一個不帶任何引數的Bochs並執行之,那麼Bochs將在當前目錄順序尋找以下檔案作為預設配置檔案:
.bochsrc
bochsrc
bochsrc.txt
bochsrc.bxrc(僅對windows有效)”
意思是配置檔案存放位置為你當前的工作目錄,即存放.bin .asm .img的資料夾。
於是我在工作目錄下新建 bochsrc 檔案,如書中程式碼2.1所示,並更改路徑匹配我電腦中的bochs
#Configuration file for Bochs #how much memory the emulated machine will have
megs: #filename of ROM images
romimage: file=$BXSHARE/BIOS-bochs-latest
vgaromimage: file=$BXSHARE/VGABIOS-lgpl-latest #what disk images will be used
floppya: 1_44=a.img, status=inserted #choose the boot disk.
boot: floppy #where do we send log messages
log: bochsout.txt #disable the mouse
mouse: enabled= #enable key mapping, using US layout as default
keyboard_mapping: enabled=, map=/usr/local/share/bochs/keymaps/x11-pc-us.map
第7,8行的romimage和vgaromimage對應真實機器的BIOS和VGA BIOS,路徑該如何設定呢?
(注:此處不同系統,不同軟體版本下,路徑可能會有差異)
方法一:在我的電腦裡 /usr/local/share/doc/bochs下有示例檔案,名為bochsrc-sample.txt,開啟之後,查詢romimage和vgaromimage可得到路徑;
方法二:以23行的map為例,用find命令,在/usr資料夾下查詢x11-pc-us.map即可
find -name x11-pc-us.map
配置檔案寫好之後,在當前目錄下輸入bochs,可看到:
========================================================================
Bochs x86 Emulator 2.4.
Build from CVS snapshot, on April ,
========================================================================
00000000000i[ ] reading configuration from bochsrc
------------------------------
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. . Restore factory default configuration
. Read options from...
. Edit options
. Save options to...
. Restore the Bochs state from...
. Begin simulation
. Quit now Please choose one: []
此時預設選項為6. Begin simulation
回車,彈出Bochs虛擬機器介面,成功!
(注:若缺少配置檔案,預設選項為2;若配置檔案錯誤,則會報錯)
參考資料: http://www.cnblogs.com/sobe/archive/2010/09/05/1818367.html
http://m.blog.csdn.net/blog/u010066564/26068283