Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2112665
  • 博文数量: 438
  • 博客积分: 3871
  • 博客等级: 中校
  • 技术积分: 6075
  • 用 户 组: 普通用户
  • 注册时间: 2011-09-10 00:11
个人简介

邮箱: wangcong02345@163.com

文章分类

全部博文(438)

文章存档

2017年(15)

2016年(119)

2015年(91)

2014年(62)

2013年(56)

2012年(79)

2011年(16)

分类: LINUX

2016-08-15 16:03:41

1. ubuntu下bochs源码编译安装
用apt-get install 安装的bochs是不带调试功能的,所以需要源码重新编译安装bochs
1.1 源码编译
  1. cong@msi:/work/os/bochs-2.6.8$ mkdir install           -->将install后的bochs放在这个目录下
  2. cong@msi:/work/os/bochs-2.6.8$ ./configure --prefix=`pwd`/install --enable-debugger --enable-disasm   -->配置成可调试
  3. cong@msi:/work/os/bochs-2.6.8$ make -j16 && make install               
  4. cong@msi:/work/os/bochs-2.6.8$ ls install               
  5. bin share

  6. cong@msi:/work/os/bochs-2.6.8$ cd install/bin/
  7. cong@msi:/work/os/bochs-2.6.8/install/bin$ ls          -->编译安装完成后会在install目录下生成bochs及bximage这两个文件   
  8. bochs bximage
1.2 配置bochsrc文件
  1. cong@msi:/work/os/bochs-2.6.8/install/bin$ cp -arf ../share/doc/bochs/bochsrc-sample.txt .
  2. cong@msi:/work/os/bochs-2.6.8/install/bin$ diff ./bochsrc bochsrc-sample.txt
  3. 186,187c186
  4. < #cpu: model=core2_penryn_t9600, count=1, ips=50000000, reset_on_triple_fault=1, ignore_bad_msrs=1, msrs="msrs.def"
  5. < cpu: model=pentium, count=1, ips=50000000, reset_on_triple_fault=1, ignore_bad_msrs=1, msrs="msrs.def"
  6. ---
  7. > cpu: model=core2_penryn_t9600, count=1, ips=50000000, reset_on_triple_fault=1, ignore_bad_msrs=1, msrs="msrs.def"
  8. 715,716c714
  9. < #ata0-master: type=disk, mode=flat, path="30M.sample"
  10. < ata0-master: type=disk, mode=flat, path="/work/os/code/disk.img"
  11. ---
  12. > ata0-master: type=disk, mode=flat, path="30M.sample"
  13. 909c907
  14. < #sound: driver=default, waveout=/dev/dsp. wavein=, midiout=
  15. ---
  16. > sound: driver=default, waveout=/dev/dsp. wavein=, midiout=
  17. 920c918
  18. < #speaker: enabled=1, mode=sound
  19. ---
  20. > speaker: enabled=1, mode=sound
注意: 上面硬盘的路径固定放在/work/os/code/disk.img下
1.3 配置脚本运行bochs
  1. cong@msi:/work/os/bochs-2.6.8/install/bin$ cd /usr/local/bin/
  2. cong@msi:/usr/local/bin$ 
  3. cong@msi:/usr/local/bin$ cat bochs
  4. #!/bin/sh
  5. /work/os/bochs-2.6.8/install/bin/bochs -f /work/os/bochs-2.6.8/install/bin/bochsrc
注意: 上面bochs的启动脚本也是固定路径,所以这些东东配置完成后就不能够再改路径了

2. 测试
2.1 测试程序
  1. cong@msi:/work/os/code/1mbr$ cat mbr.S     --> 只有4行
  2. org 0x7C00
  3.     jmp $
  4. times 510-($-$$) db 0
  5. dw 0xaa55
  6. ; dw 0x55aa
2.2 Makefile
  1. cong@msi:/work/os/code/1mbr$ cat Makefile
  2. mbr:
  3.     nasm mbr.S -o mbr.bin
  4. flash:
  5.     -rm ../disk.img                        -->前面加-的作用是如果disk.img不存在,rm执行出错也不会影响下面的操作
  6.     dd if=/dev/zero of=../disk.img bs=1M count=30
  7.     dd if=./mbr.bin of=../disk.img bs=512 count=1 conv=notrunc
2.3 编译及烧写
  1. cong@msi:/work/os/code/1mbr$ make
  2. nasm mbr.S -o mbr.bin
  3. cong@msi:/work/os/code/1mbr$ file ./mbr.bin
  4. ./mbr.bin: x86 boot sector                        -->file能正确的识别出这是一个boot sector就说明成功

  5. cong@msi:/work/os/code/1mbr$ make flash
  6. rm ../disk.img
  7. rm: cannot remove ‘../disk.img’: No such file or directory    -->这个rm删除错误不影响下面的指令
  8. make: [flash] Error 1 (ignored)
  9. dd if=/dev/zero of=../disk.img bs=1M count=30
  10. 30+0 records in
  11. 30+0 records out
  12. 31457280 bytes (31 MB) copied, 0.0154234 s, 2.0 GB/s
  13. dd if=./mbr.bin of=../disk.img bs=512 count=1 conv=notrunc
  14. 1+0 records in
  15. 1+0 records out
  16. 512 bytes (512 B) copied, 7.6391e-05 s, 6.7 MB/s
2.4 运行
  1. cong@msi:/work/os/code/1mbr$ bochs
  2. ========================================================================
  3.                        Bochs x86 Emulator 2.6.8                    -->注意apt-get install 安装的是2.4.*,源码安装的是2.6.8
  4.                 Built from SVN snapshot on May 3, 2015
  5.                   Compiled on Aug 15 2016 at 15:49:17
  6. ========================================================================
  7. 00000000000i[ ] BXSHARE not set. using compile time default '/work/os/bochs-2.6.8/install/share/bochs'   
  8. 00000000000i[ ] reading configuration from /work/os/bochs-2.6.8/install/bin/bochsrc                    -->这个是配置的bochsrc路径
  9. 00000000000e[ ] /work/os/bochs-2.6.8/install/bin/bochsrc:716: ataX-master/slave CHS set to 0/0/0 - autodetection enabled
  10. ------------------------------
  11. Bochs Configuration: Main Menu
  12. ------------------------------

  13. This is the Bochs Configuration Interface, where you can describe the
  14. machine that you want to simulate. Bochs has already searched for a
  15. configuration file (typically called bochsrc.txt) and loaded it if it
  16. could be found. When you are satisfied with the configuration, go
  17. ahead and start the simulation.

  18. You can also start bochs with the -q option to skip these menus.

  19. 1. Restore factory default configuration
  20. 2. Read options from...
  21. 3. Edit options
  22. 4. Save options to...
  23. 5. Restore the Bochs state from...
  24. 6. Begin simulation
  25. 7. Quit now

  26. Please choose one: [6]
  27. 00000000000i[ ] installing x module as the Bochs GUI
  28. 00000000000i[ ] using log file bochsout.txt
  29. Next at t=0
  30. (0) [0x0000fffffff0] f000:fff0 (unk. ctxt): jmpf 0xf000:e05b ; ea5be000f0
  31. <bochs:1> b 0x7C00                           -->在0x7C00处设断点
  32. <bochs:2> c
  33. (0) Breakpoint 1, 0x00007c00 in ?? ()
  34. Next at t=156815929
  35. (0) [0x000000007c00] 0000:7c00 (unk. ctxt): jmp .-2 (0x00007c00) ; ebfe
  36. <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 打印几个字符
  1. cong@msi:/work/os/code/1mbr$ cat mbr.S
  2. org 0x7C00
  3.     mov ax, cs
  4.     mov ds, ax
  5.     mov es, ax
  6.     mov ss, ax
  7.     mov ax, 0xb800
  8.     mov gs, ax


  9.     mov byte [gs:0x00], '1'
  10.     mov byte [gs:0x01], 0xA4
  11.     
  12.     mov byte [gs:0x02], ' '
  13.     mov byte [gs:0x03], 0xA4

  14.     mov byte [gs:0x04], 'M'
  15.     mov byte [gs:0x05], 0xA4

  16.     mov byte [gs:0x06], 'B'
  17.     mov byte [gs:0x07], 0xA4
  18.     
  19.     mov byte [gs:0x08], 'R'
  20.     mov byte [gs:0x09], 0xA4

  21.     jmp $
  22. times 510-($-$$) db 0
  23. dw 0xaa55
3.2 配置好后,编译及运行就相当简单了
  1. cong@msi:/work/os/code/1mbr$ make            -->编译
  2. nasm mbr.S -o mbr.bin
  3. cong@msi:/work/os/code/1mbr$ make flash      -->刷到disk.img中
  4. rm ../disk.img
  5. dd if=/dev/zero of=../disk.img bs=1M count=30
  6. 30+0 records in
  7. 30+0 records out
  8. 31457280 bytes (31 MB) copied, 0.0179666 s, 1.8 GB/s
  9. dd if=./mbr.bin of=../disk.img bs=512 count=1 conv=notrunc
  10. 1+0 records in
  11. 1+0 records out
  12. 512 bytes (512 B) copied, 8.0688e-05 s, 6.3 MB/s
  13. cong@msi:/work/os/code/1mbr$ bochs            -->这儿运行的是从源码编出来的bochs


附录:
1. 每次运行bochs时都会在当前目录下生成bochsout.txt
bochsrc的L761:  将bochsout.txt --> log: /tmp/bochsout.txt
这样每次运行bochs时会bochsout.txt就放在了/tmp目录下

阅读(1426) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~