前言:本機環境ubuntu 14.04 bochs 2.4.5
一.下載
官網 http://bochs.sourceforge.net/
二.安裝
1.將下載好的壓縮包解壓並進入該目錄
tar vxzf bochs-2.4.5.tar.gz cd bochs-2.4.5
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.0-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
1 #Configuration file for Bochs 2 3 #how much memory the emulated machine will have 4 megs: 32 5 6 #filename of ROM images 7 romimage: file=$BXSHARE/BIOS-bochs-latest 8 vgaromimage: file=$BXSHARE/VGABIOS-lgpl-latest 9 10 #what disk images will be used 11 floppya: 1_44=a.img, status=inserted 12 13 #choose the boot disk. 14 boot: floppy 15 16 #where do we send log messages 17 log: bochsout.txt 18 19 #disable the mouse 20 mouse: enabled=0 21 22 #enable key mapping, using US layout as default 23 keyboard_mapping: enabled=1, 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.5 Build from CVS snapshot, on April 25, 2010 ======================================================================== 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. 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: [6]
此時默認選項為6. Begin simulation
回車,彈出Bochs虛擬機界面,成功!
(注:若缺少配置文件,默認選項為2;若配置文件錯誤,則會報錯)
參考資料: http://www.cnblogs.com/sobe/archive/2010/09/05/1818367.html