「Bochs」- 配置及使用(在 Linux 下)

执行执行汇编语言的编译输出

emulation – How can I use Bochs to run Assembly code? – Stack Overflow

比如,我们编写有效的(0xaa55)引导程序,我们需要运行它,以进行调试:

第一步、编译引导程序

nasm -o main.img main.asm

注意,我们省略引导程序内容,请保证你的引导程序是有效的。

第二步、创建 .bochsrc 文件

printf 'ata0-master: type=disk, path="main.img", mode=flat, cylinders=1, heads=1, spt=1
boot: disk
' > .bochsrc

第三步、启动 bochs 模拟

bochs -q -f .bochsrc

常用指令及调试方法

Bochs User Manual

Instructions Description
s 执行下条指令
b 0x7c00 设置断点,然后使用 c 指令来执行到断点
c 执行到断点处
r 查看通用寄存器内容
sreg 查看段寄存器内容
creg 查看控制寄存器内容
info gdt 查看 GDTR 内容
   
q 退出

禁用 Debugger 功能

Bochs x86 PC emulator / Thread: [Bochs-developers] How to disable the bochs debugger
Bochs x86 PC emulator / Thread: Re: [Bochs-developers] How to disable the bochs debugger
Installation
3.4. Compiling Bochs

系统环境:Debian GNU/Linux 10 (buster)
软件版本:Bochs x86 Emulator 2.6.9

当启动 Bochs 之后,进入调试模式,显示命令提示符。即使使用 -q 选项,也只能跳过启动菜单。

我们希望可以将其当作模拟器来运行,即直接执行程序而不进入调试模式。

解决方法

目前(11/11/2020)没有选项来禁止进入 Debugger 模式。

方法一、重新编译(推荐)

重新编译 Bochs 命令,并不要启用 –enable-debugger 选项。

# 第一步、下载二进制文件
# https://sourceforge.net/projects/bochs/files/bochs/

# 第二步、编译安装
./cofigure
make
make install

方法二、使用 -rc 选项

通过 -rc 选项,将要执行的命令写入文件,并传递给 Bochs 执行。