安装步骤
环境
CentOS release 7.5.1804
gcc version 4.8.5
依赖库安装
sudo yum install gtk2 gtk2-devel
sudo yum install libXt libXt-devel
sudo yum install libXpm libXpm-devel
sudo yum install SDL SDL-devel
( sudo yum install libXrandr-devel.x86_64 )
( yum install xorg-x11-server-devel )
源码配置和安装
获取和解压
源码地址:https://sourceforge.net/projects/bochs/files/bochs/2.6.8/
wget https://sourceforge.net/projects/bochs/files/bochs/2.6.8/bochs-2.6.8.tar.gz
tar xvfz bochs-2.6.8.tar.gz
配置
./configure --enable-ne2000 \
--enable-all-optimizations \
--enable-cpu-level=6 \
--enable-x86-64 \
--enable-vmx=2 \
--enable-pci \
--enable-usb \
--enable-usb-ohci \
--enable-e1000 \
--enable-debugger \
--enable-debugger-gui \
--enable-disasm \
--with-sdl \
--with-x11
错误解决方案
若遇到以下问题
checking how to run the C++ preprocessor...
/lib/cpp
configure: error: in `/home/shupan/source/bochs-2.6.8':
configure: error: C++ preprocessor "/lib/cpp" fails sanity check
缺少相关头文件,执行以下命令解决
sudo yum install glibc-headers gcc-c++
若出现以下错误
sdl.cc:36:17: fatal error: SDL.h: No such file or directory
#include
^
compilation terminated.
则执行: sudo yum install SDL SDL-devel
出现其他错误类似,yum search xxx, 然后再安装
安装
sudo make && make install
添加环境变量
export BXSHARE=/usr/local/share/bochs
(可写入到~/.bash_profile中,记得source)
若安装在非系统目录下,则还需添加PATH环境变量,如
export PATH="$PATH:$HOME/opt/bochs/bin"
镜像文件制作
执行:bximage
依次键入:
1
fd
Enter
boot.img
汇编程序编写
vim boot.asm
org 07c00h ;告诉编译器,程序加载到内存地址07c00h
mov ax,cs
mov ds,ax
mov es,ax
call DispStr ;调用显示字符串例程
jmp $ ;无限循环
DispStr:
mov ax,BootMessage
mov bp,ax ;es:bp = 字符串地址
mov cx,16 ;cx = 字符串长度
mov ax,01301h ; ah = 13h, al = 01h
mov bx,000ch ;页号为0(bh = 0) 黑底红字(bl = 0Ch,高亮)
mov dl,0
int 10h ;10h号中断
ret
BootMessage: db "Hello, OS World!"
times 510-($-$$) db 0 ;填充剩下的空间,使生成的二进制代码恰好为512字节
dw 0xaa55 ;MBR结束标志
安装nasm
sudo yum install nasm
编译镜像文件
nasm boot.asm -o boot.bin
dd if=boot.bin of=boot.img bs=512 count=1 conv=notrunc
bochsrc配置
vim .bochsrc 【注意加载顺序】
# how much memory the emulated machine will have
megs: 32
# filename of ROM images
# BIOS已经修改,地址可以不加,可以根据文件大小进行推断,如里加地址要与文件大小相匹配
romimage: file=$BXSHARE/BIOS-bochs-latest
vgaromimage: file=$BXSHARE/VGABIOS-lgpl-latest
# what disk images will be used
# 配置镜像名
floppya: 1_44=boot.img, status=inserted
# choose the boot disk.
boot: a
# where do we send log messages?
log: run.log
# disable the mouse, since Finix is text only
mouse: enabled=0
# enable key mapping, using US layout as default.
# 键盘的映射方式也改变了
keyboard: keymap=$BXSHARE/keymaps/x11-pc-us.map
加载执行
bochs -f .bochsrc
注意:需要有对应的库和图形界面,若连接远程或者没有对应的图形界面库,则会报如下错误(当时采坑了好久)
>>PANIC<< Cannot connect to X display
是本机,不是远程。 需要展示图形界面。
选6
再按C (continue)继续执行,展示如下界面,
展示出 “Hello,OS World!"
参考资料
https://www.cnblogs.com/pro-love/p/10947790.html
https://sourceforge.net/projects/bochs/files/bochs/2.6.8/