1. bochs所需环境
安装sdl库
1 | brew install sdl |
2. 安装bochs
用brew默认安装最新版,我这里是Bochs x86 Emulator 2.6.9
1 | brew install bochs |
3. 终端测试
终端输入1
bochs
若看到1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44========================================================================
Bochs x86 Emulator 2.6.9
Built from SVN snapshot on April 9, 2017
Compiled on Dec 23 2018 at 17:15:13
========================================================================
00000000000i[ ] LTDL_LIBRARY_PATH not set. using compile time default '/usr/local/Cellar/bochs/2.6.9_2/lib/bochs/plugins'
00000000000i[ ] BXSHARE not set. using compile time default '/usr/local/Cellar/bochs/2.6.9_2/share/bochs'
00000000000i[ ] lt_dlhandle is 0x7fd7cc600220
00000000000i[PLUGIN] loaded plugin libbx_usb_common.so
00000000000i[ ] lt_dlhandle is 0x7fd7cc40ee00
00000000000i[PLUGIN] loaded plugin libbx_unmapped.so
00000000000i[ ] lt_dlhandle is 0x7fd7cc529eb0
00000000000i[PLUGIN] loaded plugin libbx_biosdev.so
00000000000i[ ] lt_dlhandle is 0x7fd7cc6007e0
00000000000i[PLUGIN] loaded plugin libbx_speaker.so
00000000000i[ ] lt_dlhandle is 0x7fd7cc600e30
00000000000i[PLUGIN] loaded plugin libbx_extfpuirq.so
00000000000i[ ] lt_dlhandle is 0x7fd7cc6012c0
00000000000i[PLUGIN] loaded plugin libbx_parallel.so
00000000000i[ ] lt_dlhandle is 0x7fd7cc602810
00000000000i[PLUGIN] loaded plugin libbx_serial.so
00000000000i[ ] lt_dlhandle is 0x7fd7cc605840
00000000000i[PLUGIN] loaded plugin libbx_iodebug.so
------------------------------
Bochs Configuration: Main Menu
------------------------------
This is the Bochs Configuration Interface, where you can describe the
machine that you want to simulate. Bochs has already searched for a
configuration file (typically called bochsrc.txt) and loaded it if it
could be found. When you are satisfied with the configuration, go
ahead and start the simulation.
You can also start bochs with the -q option to skip these menus.
1. Restore factory default configuration
2. Read options from...
3. Edit options
4. Save options to...
5. Restore the Bochs state from...
6. Begin simulation
7. Quit now
Please choose one: [2]
则说明,安装成功。
4. 测试“Hello world”输出
4.1 构建bochsrc.txt
配置文件
因为homebrew
安装的软件路径都在
1 | /usr/local/Cellar/ |
文件夹下;我们找到bochs中的bochsrc-sample.txt
文件在
1 | /usr/local/Cellar/bochs/2.6.9_2/share/doc/bochs/bochsrc-sample.txt |
复制,粘贴到新建文件夹(用来做os lab)的地方。
4.2 修改bochsrc-sample.txt
部分代码为bochsrc.txt
找到如下两行并注释掉:
1 | sound: driver=default, waveout=/dev/dsp. wavein=, midiout= |
检查如下几处并做改为(记得某一名称只能出现一次,其余注释):
1 | romimage: file=$BXSHARE/BIOS-bochs-latest |
4.3 新建镜像文件,用以模拟硬件
首先,bximage命令创建一个软盘镜像a.img(对应配置文件中的floppya):
即建立成功。
4.4 构建引导程序
1 | org 0x7c00 |
编译:
1 | nasm boot.asm -o boot.bin |
记得保证之前的
a.img
,boot.bin
,boot.asm
,bochsrc.txt
在一个文件夹下
将引导程序写进软盘镜像
1 | dd if=boot.bin of=a.img bs=512 count=1 conv=notrunc |
4.5 测试
启动bochs
bochs -f 配置文件位置
1 | bochs -f bochsrc.txt |
也可直接运行bochs ,进入后键入2来更改配置文件路径,键入6运行虚拟机
1 | fzy@fuujiro-MacBook-Pro ~/fuujiro/fuujiroCode/OS_lab bochs -f bochsrc.txt |