本文参考文挡:
http://hankjin.blog.163.com/blog/static/33731937201001902924834/
http://dev.firnow.com/course/6_system/linux/Linuxjs/20090303/156915.html
http://ubuntuforums.org/showthread.php?t=293350&page=2
http://cax.bloghi.com/2006/08/03/makefile-am-makefile-in-makefilea-a-a-e-a-c.html
说用bochs调试操作系统效果很好,所以也想看看到底是怎么回事.安装编译过程中碰到一些问题,所以记录下来,希望对自己和别人都有所帮助.
使用的操作系统为ubuntu10.04.
1:
安装步骤:
sudo apt-get install build-essential
sudo apt-get install bochs vgabios bochs-x bochsbios bochs-doc
直接通过sudo apt-get install命令安装(具体操作见下)的只是bochs执行程序,而不包含调试功能.所以若想调试操作系統或其他镜像文件,需要重新编译bochs安装包.
安装完成后通过bochs -q -f ‘bochsrc.bxrc’执行.img文件
通过bochsdbg -q -f ‘bochsrc.bxrc’调试.img文件,bochsdbg需要重新编译bochs安装包生成
2:
a: sudo apt-get source bochs //获取最新的安装包到当前目录.
我获取到的是bochs-2.4.2. //网上一些实例为bochs-2.3.7
b: cd bochs-2.4.2
查看是否有Makefile文件,我的安装包里没有,只有Makefile.in文件,因此若直接用make,则需生成Makefile文件.
c: ./configure –enable-debugger –enable-disasm –prefix=/usr //生成Makefile,将调试功能包含.
./configure的时候,可能会出现错误.最后一行提示“Error: x windows is selected, but can’t find x windows libraries. “的错误.
通过 sudo apt-get build-dep bochs解决.重新执行c步轴
d: make //生成bochs
make的时候可能会提示docbook方面的错误,通过
sudo apt-get build-dep docbook 解决.
e: sudo cp bochs /usr/bin/bochsdbg //此时可通过bochsdbg -q -f ‘bochsrc.bxrc’来调试.img文件了
3:bochsrc.bxrc文件,bochs环境搭建碰到的问题请看
http://dev.firnow.com/course/6_system/linux/Linuxjs/20090303/156915.html,我觉得讲的很好,可以参靠!
怕原文链接访问不了,故摘抄重要部分如下:
bochs -q -f ‘bochsrc.bxrc’
果然,出现如下错误:
========================================================================
Bochs x86 Emulator 2.3.7
Build from CVS snapshot, on June 3, 2008
========================================================================
00000000000i[ ] LTDL_LIBRARY_PATH not set. using compile time default ‘/usr/lib/bochs/plugins’
00000000000i[ ] BXSHARE not set. using compile time default ‘/usr/share/bochs’
00000000000i[ ] reading configuration from bochsrc.bxrc
00000000000e[ ] bochsrc.bxrc:190: unknown parameter for parport1 ignored.
00000000000p[ ] >>PANIC<< bochsrc.bxrc:281: directive ‘floppy_command_delay’ not understood
00000000000e[CTRL ] notify called, but no bxevent_callback function is registered
00000000000i[CTRL ] quit_sim called with exit code 1
这个文档毕竟是别人的,别人根据自己的机器调试的。所以这个只是指引我们前进的路灯而已,接下来就是开始改了。普通的bochsrc:
romimage: file=$BXSHARE/BIOS-bochs-latest, address=0xf0000
vgaromimage: file=$BXSHARE/VGABIOS-lgpl-latest
但是在Ubuntu下压根就没有VGABIOS-lgpl-latest
例如:
/usr/share/bochs$ ls
BIOS-bochs-latest BIOS-bochs-legacy BIOS-qemu-latest keymaps
后来我才发现,从终端下安装bochs时它把VGA专门作为了一个程序安装在了/usr/share/vgabios/中了。 /usr/share/bochs$ ls /usr/share/vgabios/
vgabios.bin vgabios.cirrus.bin vgabios.cirrus.debug.bin vgabios.debug.bin
根据出错信息
BXSHARE not set. using compile time default ‘/usr/share/bochs’,这是我的出发点,文件中有这么一行:
romimage: file=$BXSHARE\BIOS-bochs-latest, address=0xf0000
不知大家发现什么问题没有,这是个细节:$BXSHARE后跟的是“\”,我的环境是ubuntu,linux环境中需要的是“/” 所以替换为:
romimage: file=/usr/share/bochs/BIOS-bochs-latest, address=0xf0000
同理,将文档中还有一处“$BXSHARE”:
vgaromimage: file=$BXSHARE\vgabios/VGABIOS-elpin-2.40 将这行替换为:
vgaromimage: file=/usr/share/vgabios/vgabios.bin
其中一行出错信息为:00000000000p[ ] >>PANIC<< bochsrc.bxrc:281: directive ‘floppy_command_delay’ not understood
,当然了google是强大的。在bochsrc.bxrc文档中,将这行注释掉,再试试。得,又出错了:
========================================================================
Event type: PANIC
Device: [MEM0 ]
Message: ROM: System BIOS must end at 0xfffff
A PANIC has occurred. Do you want to:
cont – continue execution
alwayscont – continue execution, and don’t ask again.
This affects only PANIC events from device [MEM0 ]
die – stop execution now
abort – dump core
debug – hand control to gdb
Choose one of the actions above: [die]
其中一行出错信息为:
Message: ROM: System BIOS must end at 0xfffff
这又是一个出发点,查google:
因为不同的版本会有不同的值
bochsrc_sample.txt说明如下:
#=======================================================================
# ROMIMAGE:
# The ROM BIOS controls what the PC does when it first powers on.
# Normally, you can use a precompiled BIOS in the source or binary
# distribution called BIOS-bochs-latest. The ROM BIOS is usually loaded
# starting at address 0xf0000, and it is exactly 64k long. Another option
# is 128k BIOS which is loaded at address 0xe0000.
# You can also use the environment variable $BXSHARE to specify the
# location of the BIOS.
# The usage of external large BIOS images (up to 512k) at memory top is
# now supported, but we still recommend to use the BIOS distributed with
# Bochs. Now the start address can be calculated from image size.
#=======================================================================
romimage: file=/usr/local/share/bochs/BIOS-bochs-latest
所以最省心的方法是去掉address=0xf0000
OK,环境搭建完成。