引导程序调试软件bochs,跟配套的linux0.11内核img下载地址分别是:

http://sourceforge.net/projects/bochs/
http://www.oldlinux.org/Linux.old/bochs/linux-0.11-devel-040329.zip

调试环境的的建立

下载linux-0.11-devel-040329.zip,解压缩

其中包含一个bochs2.X的安装程序和linux内核img,

1 、找到bochsrc-hd.bxrc文件的12、36行,替换其中的$ BXSHARE为bochs的安装路径,如果就是上级目录,则可直接改为“..”,如:
#romimage: file=$BXSHARE\BIOS-bochs-latest, address=0xf0000
romimage: file=..\bochs\Bochs-2.3\BIOS-bochs-latest, address=0xf0000

2 、在添加run.bat文件,内容为:
"..\bochs\Bochs-2.3\bochsdbg" -q -f bochsrc-Hd.bxrc
运行run.bat,即启动调试工具bochsdbg。
调试

run.bat运行之后

E:\linux011\linux-0.11-devel-040329>"..\bochs\Bochs-2.3\bochsdbg" -q -f bochsrc-Hd.bxrc
00000000000i[APIC?] local apic in  initializing
========================================================================
Bochs x86 Emulator 2.3
Build from CVS snapshot on August 27, 2006
========================================================================
00000000000i[     ] reading configuration from bochsrc-Hd.bxrc
00000000000i[     ] WARNING: syntax has changed, please use 'vgaromimage: file=...' now
00000000000e[     ] bochsrc-Hd.bxrc: unknown parameter for parport1 ignored.
00000000000e[     ] bochsrc-Hd.bxrc: floppy_command_delay is DEPRECATED (now using hardware timing).
00000000000e[     ] bochsrc-Hd.bxrc: ips directive is DEPRECATED (use cpu directive parameter 'ips').
00000000000i[     ] installing win32 module as the Bochs GUI
00000000000i[     ] using log file bochsout.txt
Next at t=0
(0) [0xfffffff0] f000:fff0 (unk. ctxt): jmp far f000:e05b         ; ea5be000f0
<bochs:1>

此时Bochs调试系统已经准备好开始运行,CPU执行指针已指向ROM BIOS中地址0x000fffff0处的指令处。其中'<bochs:1>'是命令输入提示符,其中的数字表示当前的命令序列号。在命令提 示符'<bochs:1>'后面键入'help'命令,可以列出调试系统的基本命令。若要了解某个命令的具体使用方法,可以键入'help' 命令并且后面跟随一个用单引号括住的具体命令,例如:“help 'vbreak'”,如下面所示。

<bochs:1> help
help - show list of debugger commands
help 'command'- show short command description
-*- Debugger control -*-
help, q|quit|exit, set, instrument, show, trace-on, trace-off,
record, playback, load-symbols, slist
-*- Execution control -*-
c|cont, s|step|stepi, p|n|next, modebp
-*- Breakpoint management -*-
v|vbreak, lb|lbreak, pb|pbreak|b|break, sb, sba, blist,
bpe, bpd, d|del|delete
-*- CPU and memory contents -*-
x, xp, u|disas|disassemble, r|reg|registers, setpmem, crc, info, dump_cpu,
set_cpu, ptime, print-stack, watch, unwatch, ?|calc
<bochs:2> help 'vbreak'
help vbreak
vbreak seg:off - set a virtual address instruction breakpoint
<bochs:3>
为了让Bochs直接模拟执行到Linux的引导启动程序开始处,我们可以先使用断点命令在0x7c00处设置一个断点,然后让系统连续运行到0x7c00处停下来。执行的命令序列如下:
<bochs:3> vbreak 0x0000:0x7c00
<bochs:4> c
(0) Breakpoint 1, 0x7c00 (0x0:0x7c00)
Next at t=4409138
(0) [0x00007c00] 0000:7c00 (unk. ctxt): mov ax, 0x7c0             ; b8c007
<bochs:5>

下面是一些常用的指令:
info r                                  # 查看当前CPU寄存器的内容
u /10                                    # 反汇编从当前地址开始的10条指令。
print-stack                            # 显示当前堆栈的内容
dump_cpu                               # 显示CPU中的所有寄存器和状态值
lb 0xd1ec                              # 设置线性地址断点。
c                                      # 连续执行。
s                                      # 单步执行。

posted on 2017-12-14 10:18  学习记录园  阅读(820)  评论(0编辑  收藏  举报