最近在看操作系统及内核的一些内容,找到一本书写自己的操作系统,顺手练习,但是Mac10.10系统安不上Bochs啊,找了半天在StackFlow上找到了答案。Bochs的下载地址。
Mac10.10 Bochs的安装
0x01 安装SDL库
在http://www.libsdl.org安装,或者使用Homebrew来进行安装。Homebrew的安装命令brew install sdl
。
0x02 Configure Bochs
简单的解压命令tar -xvf bochs-2.6.tar.gz
后,Configure需要的参数:
./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-disasm \
--disable-debugger-gui \
--with-sdl \
--prefix=$HOME/opt/bochs
其中,
--disable-debugger-gui
被加入的原因是,debugger GUI需要使用GTK+库,但是Mac OS X默认没有安装GTK+,所以就不启用debugger GUI了。
0x03 Building and Installing Bochs
Configure好以后,常规的安装。
make
make install
安装完成后,可以加入环境变量一些内容
export BXSHARE="$HOME/opt/bochs/share/bochs"
export PATH="$PATH:$HOME/opt/bochs/bin"
Bochs的使用
因为在上面禁用了debuger GUI,所以使用bochs只能通过shell来进行了。使用《自己动手写操作系统》笔记中生成的软盘镜像来做一个系统来启动,它会产生一个输出Hello, OS World!
。结果如下图:
在bochs的安装目录下,有share/doc/bochs/bochsrc-sample.txt
这个配置文件模板,可以拷贝出来修改,目前先做一个配置文件如下:
###############################################################
# Configuration file for Bochs(Linux)
###############################################################
# filename of ROM images
romimage: file=$BXSHARE/BIOS-bochs-latest
# VGAROMIMAGE
# You now need to load a VGA ROM BIOS into C0000.
vgaromimage: file=$BXSHARE/VGABIOS-lgpl-latest
# what disk images will be used
floppya: 1_44=YourIMGPath/TINIX.IMG, status=inserted
# choose the boot disk.
boot: floppy
# where do we send log messages?
log: bochsout.txt
# disable the mouse
mouse: enabled=0
# enable key mapping, using US layout as default. 注意map的路径
keyboard_mapping: enabled=0, map=YourBochsPath/keymaps/x11-pc-us.map
# how much memory the emulated machine will have
megs: 32
在shell中运行bochs
打开bochs
选择2. Read options from...
,然后输入自己刚才配置文件的位置,如我的就是/Volumes/ExtendsDisk/tmp/bochsrc.txt
,加载配置文件成功后,选择6. Begin simulation
开始模拟器,因为bochs是一个模拟器,并且会开始时下断点,我们在6
后需要再次输入命令c
,也就是continue
来运行系统,如果正常,就会显示上面那张HelloWorld的图了。给出Bochs调试命令集合:
-*- Debugger control -*-
help, q|quit|exit, set, instrument, show, trace, trace-reg,
trace-mem, u|disasm, ldsym, slist
-*- Execution control -*-
c|cont|continue, s|step, p|n|next, modebp, vmexitbp
-*- Breakpoint management -*-
vb|vbreak, lb|lbreak, pb|pbreak|b|break, sb, sba, blist,
bpe, bpd, d|del|delete, watch, unwatch
-*- CPU and memory contents -*-
x, xp, setpmem, writemem, crc, info,
r|reg|regs|registers, fp|fpu, mmx, sse, sreg, dreg, creg,
page, set, ptime, print-stack, ?|calc
-*- Working with bochs param tree -*-
show "param", restore