前言:本机环境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