bochs使用方法总结

来源:互联网 发布:哪个租房软件最靠谱 编辑:程序博客网 时间:2024/06/03 17:10

Copyright 2015 张智鹏

ubuntu14.04下bochs安装方法

  1. 去官网下载bochs2.6.7源代码
  2. 将其解压到 /usr/local/src
  3. 进入/usr/local/src/bochs-2.6.7/,输入命令

sudo ./configure –with-x11 –with-wx –enable-debugger –enable-disasm –enable-all-optimizations –enable-readline –enable-long-phy-address –enable-debugger-gui

–enable-debugger:开启调试功能
–enable-disasm:开启反汇编功能
–enable-long-phy-address:如果你是64位的系统,则需要这一句
可能会报错:

ERROR: X windows gui was selected, but X windows libraries were not found.

需要安装xorg-dev, libgtk2.0-dev等库(可能还有其它库,有点忘了)

  1. 输入命令make
    会出现如下错误:

/usr/bin/ld: gui/libgui.a(gtk_enh_dbg_osdep.o): undefined reference to symbol pthread_create@@GLIBC_2.1 //
lib/i386-linux-gnu/libpthread.so.0: error adding symbols: DSO missing from command line collect2: error: ld r

解决方法:
在bochs2.6.7目录下的Makefile文件中的LIBS下添加如下内容 :

-lz -lrt -lm -lpthread

bochs配置文件

下面两个文件是bochs的示例配置文件,里面的注释有详细的介绍(这两个文件一模一样)

/usr/local/share/doc/bochs/bochsrc-sample.txt
/usr/local/src/bochs-2.6.7/.bochsrc

也可以使用如下比较简单的配置文件:
{参考自:《Orange S:一个操作系统的实现》}

################################################################ Configuration file for Bochs################################################################ how much memory the emulated machine will havemegs: 32# filename of ROM imagesromimage: file=/usr/share/bochs/BIOS-bochs-latestvgaromimage: file=/usr/share/vgabios/vgabios.bin# what disk images will be used# 使用虚拟软盘floppya: 1_44=a.img, status=inserted# 使用虚拟硬盘# ata0-master: type=disk, path="hd_20_16_63.img", mode=flat, cylinders=20, heads=16, spt=63# choose the boot disk.# 选择虚拟软盘作为启动盘boot: floppy# 使用虚拟硬盘作为启动盘# boot: disk# where do we send log messages?log: bochsout.txt# disable the mousemouse: enabled=0# enable key mapping, using US layout as default.keyboard_mapping: enabled=1, map=/usr/share/bochs/keymaps/x11-pc-us.map

虚拟硬盘生成方法示例(软盘同理):

输入命令:bximage
选择 hd
选择 flat
选择 10m
输入虚拟硬盘映像名称 eg.hd_20_16_63.img

要注意生成的硬盘的cylinders(柱面数),heads(磁头数), spt(每个磁道的扇区数量)

Sectors = Cylinders * Heads * SectorsPerTrack = 20*16*63 (柱面 磁头 磁道 扇区)
Space = Sectors*512bytes

bochs常用调试命令

{参考bochs官网userguide以及 《x86汇编语言-从实模式到保护模式》}

Execution Control

命令 解释 c continue executing(直到某个断点) s [count] execute count instructions, default is 1 n 自动完成循环过程,并在循环体外的下一条指令前停住(例如 loop,rep movsb指令) Ctrl-C stop execution, and return to command line prompt Ctrl-D if at empty line on command line, exit q quit exit quit debugger and execution

BreakPoints

命令 解释 vb seg:off Set a virtual address instruction breakpoint lb addr Set a linear address instruction breakpoint b [*] addr或者pb [*]addr Set a physical address instruction breakpoint info break Display state of all current breakpoints delete n Delete a breakpoint

Manipulating Memory

命令 解释 x/nuf addr Examine memory at linear address addr xp/nuf addr Examine memory at physical address addr crc addr1 addr2 Show CRC32 for physical memory range addr1..addr2
  • n Count of how many units to display
  • u Unit size; one of
    • b Individual bytes
    • h Halfwords (2 bytes)
    • w Words (4 bytes)
    • g Giant words (8 bytes)

NOTE: these are not typical Intel nomenclature sizes,
but they are consistent with GDB convention.

  • f Printing format. one of

    • x Print in hexadecimal
    • d Print in decimal
    • u Print in unsigned decimal
    • o Print in octal

    n, f, and u are optional parameters. u and f default to the last values
    you used, or to w(words) and x(hex) if none have been supplied.
    n currently defaults to 1. If none of these optional parameters are
    used, no slash should be typed. addr is also optional. If you don’t
    specify it, it will be the value the next address (as if you had
    specified n+1 in the last x command).

Info commands

命令 解释 r reg regs registers List of CPU integer registers and their contents fp fpu List of all FPU registers and their contents sreg Show segment registers and their contents dreg Show debug registers and their contents creg Show control registers and their contents info cpu List of all CPU registers and their contents info eflags Show decoded EFLAGS register info break Information about current breakpoint status info tab Show paging address translation info device Show state of the specified device info gdt 显示GDT中的段描述符和门描述符 info ldt 显示当前任务的LDT中的所有内容 info tss 显示当前任务的TSS中的内容 info ldt 显示 print-stack [num words] Print the num words top 16-bit words on the stack. Num words defaults to 16. Only works reliably in protected mode when the base address of the stack segment is zero. page linearaddr 查看线性地址到物理页的映射信息

Instruction tracing

命令 解释 trace on Disassemble every executed instruction. Note that instructions which caused exceptions are not really executed, and therefore not traced. trace off Disable instruction tracing. trace-reg on 每执行一步都显示主要寄存器的值

反汇编指令

命令 解释 u/n addr 反汇编从addr开始的n条指令
0 0