1 环境说明
1.1 下载安装Bochs-2.6.11:
官网:http://bochs.sourceforge.net/ 。
下载:https://sourceforge.net/projects/bochs/files/bochs/ 。
1.2 安装centos7
使用centos7来编译汇编程序。
安装nasm:
yum -y install nasm
2. 使用介绍:
2.1 文件说明:
我们主要用到下面3个执行程序。
bochs.exe:直接运行虚拟机。
bochdbg.exe:可调试程序(带dbg)。
bximage.exe:用于生成软盘或者镜像文件的软件。可对进行参数进行调整。
2.2 bochs使用先决条件:
(1)配置文件。
(2)虚拟机镜像。
2.3 配置文件:
正常情况可以复制bochsrc-sample.txt文件为bochsrc.bxrc。
使用后缀.bxrc有利于我们点击load按钮的时候,方便加载。
当前,我使用下面的配置文件内容来测试的。
配置文件内容:
# 指定虚拟机的内存大小为32M
# 看到sample配置文件中,讲到“MEGS”选项已弃用。请改用“MEMORY”选项。自行决定。
megs:32# 指定虚拟机的BIOS镜像
romimage: file=BIOS-bochs-latest
vgaromimage: file=VGABIOS-lgpl-latest# 软盘启动及配置
floppya: 1_44="a.img", status=inserted
boot: floppy# 指定日志文件,里面有各种运行时信息
log: bochsout.txt# 不使用鼠标
mouse: enabled=0#cpu
cpu: ips=15000000
关于配置文件的命名及默认操作,偶然看到文档文件夹有这样的说明,可以参考下:
5.2. Search order for the configuration file
If no configuration file is specified on the command line and config file loading is not disabled, Bochs searches for a default configuration file. This is the search order:.bochsrc in the current directorybochsrc in the current directorybochsrc.txt in the current directory(win32 only) bochsrc.bxrc in the current directory(Unix only) .bochsrc in the user's home directory(Unix only) bochsrc in the /etc directory
官网:http://bochs.sourceforge.net/diskimages.html 。有提供一些镜像文件和配置信息,我们可以参考,关于软盘的镜像是“Pragma Linux”。
2.4 创建镜像文件
运行bximage.exe。
操作参考截图:
2.5 使用传说中的最简操作系统源码验证:
汇编源码:
org 07c00h ;告诉编译器程序加载到7c00处 mov ax, cs mov ds, ax mov es, ax call DispStr ;调用显示字符串例程 jmp $
DispStr: mov ax, BootMessage mov bp, ax mov cx, 16 mov ax, 01301h mov bx, 00ch mov dl, 0 int 10h ret
BootMessage: db "Hello, OS world!" times 510-($-$$) db 0 dw 0xaa55
新建boot.s文件,将这段源码放入boot.s中。然后在Centos7下编译。
编译命令:
nasm boot.s -o boot.bin
2.6 使用dd命令把系统拷贝到镜像中
dd if=./boot.bin of=a.img bs=512 count=1 conv=notrunc
其中if为输入的文件。of为输出的文件(写到此的文件中),bs为块的大小,count为拷贝多少个块。notrunc为当boot.bin的大小小于a.img时,此项避免将a.img截短为boot.bin的大小。
2.7 运行虚拟机
运行bochs.exe,
点击“Load”按钮选择bochsrc.bxrc文件。会在现实屏幕上看到“reading configuration from D:\Program Files\Bochs-2.6.11\bochsrc.bxrc”字样。
点击“Start”按钮。会新弹出面板界面,第一行会显示“Hello, OS world!”。