现在的位置: 首页 > 综合 > 正文

bochs & nasm的安装

2014年09月05日 ⁄ 综合 ⁄ 共 7306字 ⁄ 字号 评论关闭

缘起

最近看《Orange's 一个操作系统的实现》,需要使用使用bochs工具和nasm工具,这两个工具在Ubuntu下可以使用dpkg或者更高级的apt-get来安装:sudo apt-get install nasm      sudo apt-get install  vgabios bochs bochs-x bximage(不能调试)

但是有时候尝试一下使用源代码编译也是一个不错的注意:

编译nasm

1.从官网(http://sourceforge.net/projects/nasm/files/nasm%20sources/)上下载nasm的源码.

2. tar -xvf  nasm-2.07.tar.gz

    cd nasm-2.07

    ./configure

    make

    sudo make install

编译bochs

由于开始的时候对bochs使用的依赖项不是很熟悉,犯了很多的错误,总的来说步骤是

1,从官网上下载源码(http://sourceforge.net/projects/bochs/files/bochs/

2. 确保安装编译前的依赖项

sudo apt-get install build-essential(gcc,make基本工具支持,注意bochs是用C++写的,可能需要安装g++-sudo apt-get install g++)

sudo apt-get install libx11-dev,

sudo apt-get install libxrandr-dev,

sudo apt-get install xorg-dev(x window的图形的支持),

sudo apt-get install libgtk2.0-dev

sudo apt-get install vgabios 

3. 编译安装

 tar -xvf  bochs-2.6.2.tar.gz

 cd bochs-2.6.2

 ./configure --with-x11 --enable-debugger --enable-disasm 

 make

 sudo make install

 make clean(清除编译中产生的文件,例如*.o文件之类的,如果放着不管的话,很占空间)

备注:大概隔了2-3个月后,在使用bochs遇到了一些问题,再来看自己的写的博客时,感觉写得好烂,而且不全。bochs的安装配置很有多,通过命令./configure -h 可以查看,以下列出一些可选的特性:

Optional Features:
  --disable-option-checking  ignore unrecognized --enable/--with options
  --disable-FEATURE       do not include FEATURE (same as --enable-FEATURE=no)
  --enable-FEATURE[=ARG]  include FEATURE [ARG=yes]
  --enable-static[=PKGS]  build static libraries [default=no]
  --enable-shared[=PKGS]  build shared libraries [default=yes]
  --enable-fast-install[=PKGS]
                          optimize for fast installation [default=yes]
  --disable-libtool-lock  avoid locking (might break parallel builds)
  --enable-ltdl-install   install libltdl
  --disable-largefile     omit support for large files
  --enable-idle-hack      use Roland Mainz's idle hack (no)
  --enable-plugins        enable plugin support (no)
  --enable-a20-pin        compile in support for A20 pin (yes)
  --enable-x86-64         compile in support for x86-64 instructions (no)
  --enable-ne2000         enable NE2000 support (no)

可上面的这些选项可以看到,bochs的默认安装中还有很多的可选的特性,而且这些特性在默认中没有安装,比如usb 和 e2k之类的,然而在使用bochs时,这些特性可能是需要的,这就需要在configure时自己安装上。比如要安装ne2k插件,从而使得模拟器内的系统可以使用网络,要在 ./configure 后加上 --enable-ne2000  --enable-plugins,由于ne2k可能要访问Socket,直接运行时好像不给访问,需要用sudo提升了一下权限。

从源码种安装是有问题的,比如没有安装(vgabios)参考了资料6,据说是少安装了一个东西:bochs-x以及其他的一些配置什么的,实在太麻烦了。以及出现的是如下的X 界面:


所以,我决定尝试rpm安装包(参考7)

1.sudo apg-get install rpm

2.下载rpm安装包

3.rpm -ivh xxx.rpm时,我被一堆依赖库吓到了,算了,我就使用上面编译的好的那个bochs好了.

后来,我发现我安装的实际上是完整的没有问题的。因为半年前曾经尝试着看了《一个操作系统的实现 第二版》那本书的,当时在自己的还用着windows机器上安装了bochs和nasm,在windows下安装bochs和其他window软件一样,就是一直next,next,然后finish,然后就安装好了,windows下的bochs在安装时默认加载的是dlxlinux。

而我在Ubuntu下使用源码安装的bochs,添加了调试功能,需要在虚拟终端中键入一些命令才可以使得bochs继续运行下去:

行为

指令

举例

在某个物理地址设置断点

baddr

B0x30400

显示当前所有的断点信息

infobreak

Infobreak

继续单步执行,直到遇到断点

c

c

单步执行

s

s

单步执行(遇到函数则跳过)

n

n



查看寄存器信息

infocpu

r

fp

sreg

creg

infocpu

r

fp

sreg

creg

查看堆栈

print-stack

print-stack

查看内存物理地址内容

xp/nuf addr

xp/40bx 0x9013e

查看线性地址内容

x/nuf addr

x/40bx 0x12e

反汇编一段内存

ustart end

u0x30400 0x3040D

反汇编执行的每一条执行

trace-on

traceon

每执行一条指令就打印CPU信息

trace-reg

trace-regon

其中,由于不是很熟悉,我发现c命令挺好使用的,修改了一下bochsrc文件,使用bximage创建了一个image文件,并且从官网上下载一个freedos.img(自己动手写OS中的光盘中提供了相应的freedos.img的),运行c命令,截图如下:


关于《Orange's一个操作系统的实现》中,我使用的bochs的版本是2.6.2,因为安装的文件的路径的问题和作者的不同,书上附录中给出的bochsrc的文件需要进行一定的修改,:

###############################################################
# Configuration file for Bochs
###############################################################

# how much memory the emulated machine will have
megs: 32

# filename of ROM images
romimage: file=/usr/local/share/bochs/BIOS-bochs-latest
vgaromimage: file=/usr/share/vgabios/vgabios.bin

# what disk images will be used 

# bochs可以挂载的软盘好像只有两个,也可以通过bximage创建hard Disk的镜像文件
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=0

# enable key mapping, using US layout as default.
keyboard_mapping: enabled=1, map=/usr/local/share/bochs/keymaps/x11-pc-us.map

修改的地方使用红色字体标志出来,具体要不要修改bochsrc文件,自己到相关目录下找找看一看,或者使用locate或者find命令,find命令参数太多,而且从直接文件系统中检索的,速度比较的慢。这里推荐使用locate命令,locate命令时从Linux系统所维护的一个数据库中读取的,唯一不好的是文件数据可能不太一致,在检索之前updatedb一下比较好。具体的可以参考一下《鸟哥的Linux私房菜的基础篇》

sudo updatedb

locate vgabios.bin

检索的结果:

/usr/share/vgabios
/usr/share/doc/vgabios
/usr/share/doc/vgabios/BUGS
/usr/share/doc/vgabios/README.gz
/usr/share/doc/vgabios/TODO
/usr/share/doc/vgabios/changelog.Debian.gz
/usr/share/doc/vgabios/copyright
/usr/share/vgabios/vgabios.bin
/usr/share/vgabios/vgabios.cirrus.bin
/usr/share/vgabios/vgabios.cirrus.debug.bin
/usr/share/vgabios/vgabios.debug.bin
/usr/share/vgabios/vgabios.qxl.bin
/usr/share/vgabios/vgabios.qxl.debug.bin
/usr/share/vgabios/vgabios.stdvga.bin
/usr/share/vgabios/vgabios.stdvga.debug.bin
/usr/share/vgabios/vgabios.vmware.bin
/usr/share/vgabios/vgabios.vmware.debug.bin
/var/cache/apt/archives/vgabios_0.6c-2ubuntu3_all.deb
/var/lib/dpkg/info/vgabios.list
/var/lib/dpkg/info/vgabios.md5sums

出现的问题

在不知道bochs的依赖项前的出现的问题:

1.x11/xlib.h nosuch file or directory

sudo apt-get install libx11-dev.
2Compile error: X11/extensions/Xrandr.h: No such file or directory

sudo apt-get  install libxrandr-dev

3.fatal error: gtk/gtk.h: No such file or directory

/home/xc-pc/Downloads/bochs-2.6.2/gui/gtk_enh_dbg_osdep.cc:995:
undefined reference to `gtk_widget_destroy'

collect2: error: ld returned 1 exit status
make: *** [bochs] Error 1

`pkg-config gtk+-2.0 --cflags --lib`添加的到bochs下的Makefile的LIBS变量以及bochs下的gui的下Makefile中的LIBS中

4 吓人的rpm安装依赖包

error: Failed dependencies:
/bin/sh is needed by bochs-2.6.2-1.i586
libSDL-1.2.so.0 is needed by bochs-2.6.2-1.i586
libX11.so.6 is needed by bochs-2.6.2-1.i586
libXpm.so.4 is needed by bochs-2.6.2-1.i586
libXrandr.so.2 is needed by bochs-2.6.2-1.i586
libasound.so.2 is needed by bochs-2.6.2-1.i586
libasound.so.2(ALSA_0.9) is needed by bochs-2.6.2-1.i586
libasound.so.2(ALSA_0.9.0rc4) is needed by bochs-2.6.2-1.i586
libc.so.6 is needed by bochs-2.6.2-1.i586
libc.so.6(GLIBC_2.0) is needed by bochs-2.6.2-1.i586
libc.so.6(GLIBC_2.1) is needed by bochs-2.6.2-1.i586
libc.so.6(GLIBC_2.1.3) is needed by bochs-2.6.2-1.i586
libc.so.6(GLIBC_2.2) is needed by bochs-2.6.2-1.i586
libc.so.6(GLIBC_2.3) is needed by bochs-2.6.2-1.i586
libc.so.6(GLIBC_2.7) is needed by bochs-2.6.2-1.i586
libdl.so.2 is needed by bochs-2.6.2-1.i586
libgcc_s.so.1 is needed by bochs-2.6.2-1.i586
libgcc_s.so.1(GCC_3.0) is needed by bochs-2.6.2-1.i586
libgcc_s.so.1(GLIBC_2.0) is needed by bochs-2.6.2-1.i586
libltdl.so.7 is needed by bochs-2.6.2-1.i586
libm.so.6 is needed by bochs-2.6.2-1.i586
libm.so.6(GLIBC_2.0) is needed by bochs-2.6.2-1.i586
libncurses.so.5 is needed by bochs-2.6.2-1.i586
libpthread.so.0 is needed by bochs-2.6.2-1.i586
libpthread.so.0(GLIBC_2.0) is needed by bochs-2.6.2-1.i586
libpthread.so.0(GLIBC_2.1) is needed by bochs-2.6.2-1.i586
libpthread.so.0(GLIBC_2.2) is needed by bochs-2.6.2-1.i586
libstdc++.so.6 is needed by bochs-2.6.2-1.i586
libstdc++.so.6(CXXABI_1.3) is needed by bochs-2.6.2-1.i586
libstdc++.so.6(GLIBCXX_3.4) is needed by bochs-2.6.2-1.i586
libwx_base-2.8.so.0 is needed by bochs-2.6.2-1.i586
libwx_base-2.8.so.0(WX_2.8) is needed by bochs-2.6.2-1.i586
libwx_gtk2_core-2.8.so.0 is needed by bochs-2.6.2-1.i586
libwx_gtk2_core-2.8.so.0(WX_2.8) is needed by bochs-2.6.2-1.i586

参考资料

1.Ubuntu 安装 Bochs http://m.oschina.net/blog/56095

2.X11/Xlib.h:没有该文件或目录错误http://hi.baidu.com/linzch/item/5726f8e57073a7b42f140bd6

3.X11/Xlib.h not found in Ubuntuhttp://stackoverflow.com/questions/5299989/x11-xlib-h-not-found-in-ubuntu

4.http://hi.baidu.com/zeropointer_/item/57d8d20a38afcb90a3df43d6

5.Linux(ubuntu)安装bochs http://blog.csdn.net/sinzou1/article/details/5903968

6.bochs 2.4.2 ubuntu 安装运行问题《orange's 一个操作系统的实现》第二章 调试篇:

http://blog.csdn.net/evil_darker/article/details/5456252

7.如何在Linux上使用Bochs:http://wangcong.org/articles/bochs.html

小结

Orange‘s的那本书估计以后不会看了,虽然只看了前3章而已,原因是有其它的事情要去做,没有时间看。很多时候,我一直以为等有空了,会去做某某事情,也许永远不会有空去做某事,只是在自我安慰而已。

抱歉!评论已关闭.