1. ubuntu下bochs源码编译安装
用apt-get install 安装的bochs是不带调试功能的,所以需要源码重新编译安装bochs
1.1 源码编译
-
cong@msi:/work/os/bochs-2.6.8$ mkdir install -->将install后的bochs放在这个目录下
-
cong@msi:/work/os/bochs-2.6.8$ ./configure --prefix=`pwd`/install --enable-debugger --enable-disasm -->配置成可调试
-
cong@msi:/work/os/bochs-2.6.8$ make -j16 && make install
-
cong@msi:/work/os/bochs-2.6.8$ ls install
-
bin share
-
-
cong@msi:/work/os/bochs-2.6.8$ cd install/bin/
-
cong@msi:/work/os/bochs-2.6.8/install/bin$ ls -->编译安装完成后会在install目录下生成bochs及bximage这两个文件
-
bochs bximage
1.2 配置bochsrc文件
-
cong@msi:/work/os/bochs-2.6.8/install/bin$ cp -arf ../share/doc/bochs/bochsrc-sample.txt .
-
cong@msi:/work/os/bochs-2.6.8/install/bin$ diff ./bochsrc bochsrc-sample.txt
-
186,187c186
-
< #cpu: model=core2_penryn_t9600, count=1, ips=50000000, reset_on_triple_fault=1, ignore_bad_msrs=1, msrs="msrs.def"
-
< cpu: model=pentium, count=1, ips=50000000, reset_on_triple_fault=1, ignore_bad_msrs=1, msrs="msrs.def"
-
---
-
> cpu: model=core2_penryn_t9600, count=1, ips=50000000, reset_on_triple_fault=1, ignore_bad_msrs=1, msrs="msrs.def"
-
715,716c714
-
< #ata0-master: type=disk, mode=flat, path="30M.sample"
-
< ata0-master: type=disk, mode=flat, path="/work/os/code/disk.img"
-
---
-
> ata0-master: type=disk, mode=flat, path="30M.sample"
-
909c907
-
< #sound: driver=default, waveout=/dev/dsp. wavein=, midiout=
-
---
-
> sound: driver=default, waveout=/dev/dsp. wavein=, midiout=
-
920c918
-
< #speaker: enabled=1, mode=sound
-
---
-
> speaker: enabled=1, mode=sound
注意: 上面硬盘的路径固定放在/work/os/code/disk.img下
1.3 配置脚本运行bochs
-
cong@msi:/work/os/bochs-2.6.8/install/bin$ cd /usr/local/bin/
-
cong@msi:/usr/local/bin$
-
cong@msi:/usr/local/bin$ cat bochs
-
#!/bin/sh
-
/work/os/bochs-2.6.8/install/bin/bochs -f /work/os/bochs-2.6.8/install/bin/bochsrc
注意: 上面bochs的启动脚本也是固定路径,所以这些东东配置完成后就不能够再改路径了
2. 测试
2.1 测试程序
-
cong@msi:/work/os/code/1mbr$ cat mbr.S --> 只有4行
-
org 0x7C00
-
jmp $
-
times 510-($-$$) db 0
-
dw 0xaa55
-
; dw 0x55aa
2.2 Makefile
-
cong@msi:/work/os/code/1mbr$ cat Makefile
-
mbr:
-
nasm mbr.S -o mbr.bin
-
flash:
-
-rm ../disk.img -->前面加-的作用是如果disk.img不存在,rm执行出错也不会影响下面的操作
-
dd if=/dev/zero of=../disk.img bs=1M count=30
-
dd if=./mbr.bin of=../disk.img bs=512 count=1 conv=notrunc
2.3 编译及烧写
-
cong@msi:/work/os/code/1mbr$ make
-
nasm mbr.S -o mbr.bin
-
cong@msi:/work/os/code/1mbr$ file ./mbr.bin
-
./mbr.bin: x86 boot sector -->file能正确的识别出这是一个boot sector就说明成功了
-
-
cong@msi:/work/os/code/1mbr$ make flash
-
rm ../disk.img
-
rm: cannot remove ‘../disk.img’: No such file or directory -->这个rm删除错误不影响下面的指令
-
make: [flash] Error 1 (ignored)
-
dd if=/dev/zero of=../disk.img bs=1M count=30
-
30+0 records in
-
30+0 records out
-
31457280 bytes (31 MB) copied, 0.0154234 s, 2.0 GB/s
-
dd if=./mbr.bin of=../disk.img bs=512 count=1 conv=notrunc
-
1+0 records in
-
1+0 records out
-
512 bytes (512 B) copied, 7.6391e-05 s, 6.7 MB/s
2.4 运行
-
cong@msi:/work/os/code/1mbr$ bochs
-
========================================================================
-
Bochs x86 Emulator 2.6.8 -->注意apt-get install 安装的是2.4.*,源码安装的是2.6.8
-
Built from SVN snapshot on May 3, 2015
-
Compiled on Aug 15 2016 at 15:49:17
-
========================================================================
-
00000000000i[ ] BXSHARE not set. using compile time default '/work/os/bochs-2.6.8/install/share/bochs'
-
00000000000i[ ] reading configuration from /work/os/bochs-2.6.8/install/bin/bochsrc -->这个是配置的bochsrc路径
-
00000000000e[ ] /work/os/bochs-2.6.8/install/bin/bochsrc:716: ataX-master/slave CHS set to 0/0/0 - autodetection enabled
-
------------------------------
-
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: [6]
-
00000000000i[ ] installing x module as the Bochs GUI
-
00000000000i[ ] using log file bochsout.txt
-
Next at t=0
-
(0) [0x0000fffffff0] f000:fff0 (unk. ctxt): jmpf 0xf000:e05b ; ea5be000f0
-
<bochs:1> b 0x7C00 -->在0x7C00处设断点
-
<bochs:2> c
-
(0) Breakpoint 1, 0x00007c00 in ?? ()
-
Next at t=156815929
-
(0) [0x000000007c00] 0000:7c00 (unk. ctxt): jmp .-2 (0x00007c00) ; ebfe
-
<bochs:3>
此时bochs的gui界面卡住了。
注: 如果mbr.S中没有写对,例如把0xaa55写成了0x55aa,make flash之后会出现: No bootable device.
2.5 代码下载
1mbr.rar(下载后改名为1mbr.tar.gz)
bochsrc.rar (
下载后改名为bochsrc.tar.gz)
3. 加几个字符
3.1 打印几个字符
-
cong@msi:/work/os/code/1mbr$ cat mbr.S
-
org 0x7C00
-
mov ax, cs
-
mov ds, ax
-
mov es, ax
-
mov ss, ax
-
mov ax, 0xb800
-
mov gs, ax
-
-
-
mov byte [gs:0x00], '1'
-
mov byte [gs:0x01], 0xA4
-
-
mov byte [gs:0x02], ' '
-
mov byte [gs:0x03], 0xA4
-
-
mov byte [gs:0x04], 'M'
-
mov byte [gs:0x05], 0xA4
-
-
mov byte [gs:0x06], 'B'
-
mov byte [gs:0x07], 0xA4
-
-
mov byte [gs:0x08], 'R'
-
mov byte [gs:0x09], 0xA4
-
-
jmp $
-
times 510-($-$$) db 0
-
dw 0xaa55
3.2 配置好后,编译及运行就相当简单了
-
cong@msi:/work/os/code/1mbr$ make -->编译
-
nasm mbr.S -o mbr.bin
-
cong@msi:/work/os/code/1mbr$ make flash -->刷到disk.img中
-
rm ../disk.img
-
dd if=/dev/zero of=../disk.img bs=1M count=30
-
30+0 records in
-
30+0 records out
-
31457280 bytes (31 MB) copied, 0.0179666 s, 1.8 GB/s
-
dd if=./mbr.bin of=../disk.img bs=512 count=1 conv=notrunc
-
1+0 records in
-
1+0 records out
-
512 bytes (512 B) copied, 8.0688e-05 s, 6.3 MB/s
-
cong@msi:/work/os/code/1mbr$ bochs -->这儿运行的是从源码编出来的bochs
附录:
1. 每次运行bochs时都会在当前目录下生成bochsout.txt
改
bochsrc的L761: 将bochsout.txt --> log: /tmp/bochsout.txt
这样每次运行bochs时会bochsout.txt就放在了/tmp目录下
阅读(1484) | 评论(0) | 转发(0) |