ubuntu 安装Bochs

最近在看X86汇编语言:从实模式到保护模式这本书,书里面的程序都是在裸机上运行的,需要安装一个Bochs模拟器来运行和调试,安装过程如下:

首先是下载最新版的源码:

地址:http://bochs.sourceforge.net

解压:

tar -zxvf bochs-2.6.8.tar.gz

进入目录:

cd bochs-2.6.8

安装命令如下:

./configure --enable-debugger --enable-disasm

make

sudo make install

如果顺利的话就安装完成了,可是我自己在编译的时候出现了错误,如下:


ubuntu 安装Bochs_第1张图片


错误处理:

网上搜了一下,貌似需要安装xorg-dev。

安装步骤如下:

sudo apt-get install aptitude

sudo aptitude install xorg-dev


到处bochs就安装完成了。


运行bochs需要一个配置文件,文件名为bochsrc,内容如下:

megs:32

romimage:file=/usr/local/share/bochs/BIOS-bochs-latest

vgaromimage:file=/usr/local/share/bochs/VGABIOS-lgpl-latest

floppya:1_44=a.img,status=inserted

boot:floppy

log:bochsout.txt

mouse:enabled=0

keyboard_mapping: enabled=1, map=/usr/local/share/bochs/keymaps/x11-pc-us.map


接着还需要创建一个虚拟软盘文件,并且将程序写入到虚拟软盘文件中,才能运行。

虚拟软盘文件可以使用bximage命令创建。

具体步骤为:输入bximage命令,选择创建一个新磁盘,在选择类型时输入fd,之后全部选择默认,一直回车就可以了。

这样在当前目录下会产生一个a.img的虚拟软盘文件。

ubuntu 安装Bochs_第2张图片

汇编程序可以使用如下代码,功能是在屏幕上显示Hello, OS!

	org 0x7c00
	mov ax, cs
	mov ds, ax
	mov es, ax
	call DispStr
	jmp $
DispStr:
	mov ax, BootMessage
	mov bp, ax
	mov cx, 10
	mov ax, 0x1301
	mov bx, 0x000c
	mov dl, 0
	int 0x10
	ret
BootMessage:         db   "Hello, OS!"
times   510-($-$$)   db   0  
dw      0xaa55 


代码使用nasm编译,命令为:

nasm -f bin boot.s -o boot.bin

使用dd命令将编译产生的二进制文件写入磁盘。

dd if=boot.bin of=a.img bs=512 count=1 conv=notrunc


完成之后只要输入命令 bochs -f bochsrc 就可以运行了。


Bochs常用调试指令:



ubuntu 安装Bochs_第3张图片


你可能感兴趣的:(ubuntu 安装Bochs)