在Linux下編譯帶調試功能的Bochs

在Linux下使用Bochs參考:html

http://wangcong.org/articles/bochs.htmllinux

http://kinglaw05.blog.163.com/blog/static/59683314200911205510345/ios

 

首先,安裝libgtk2.0-dev,build-essential庫c++

   1: sudo apt-get install libgtk2.0-dev build-essential

而後下載最新的bochs源碼,解壓ubuntu

   1: sudo wget http://bochs.sourceforge.net/svn-snapshot/bochs-20140211.tar.gz
   2: sudo gzip -d bochs-20140211.tar.gz
   3: sudo tar -xvf bochs-20140211.tar
   4: cd bobochs-20140211

 

配置bash

將.conf.linux修改爲下面模樣:app

   1: #!/bin/sh
   2: #
   3: # .conf.linux
   4: #
   5:  
   6: #which_config=normal
   7: which_config=plugins
   8:  
   9: CC="gcc"
  10: CXX="c++"
  11: CFLAGS="-Wall -O3 -fomit-frame-pointer -pipe"    # for speed
  12: #CFLAGS="-Wall -g -pipe"                         # for development
  13: CXXFLAGS="$CFLAGS"
  14:  
  15: export CC
  16: export CXX
  17: export CFLAGS
  18: export CXXFLAGS
  19:  
  20:  
  21: case $which_config in
  22:  
  23:   normal)
  24:  
  25:     #######################################################################
  26:     # configuration 1 for release binary RPMs
  27:     # Include a few standard options, speed optimizations, X11 only.
  28:     #######################################################################
  29:     ./configure --enable-sb16 \
  30:                 --enable-ne2000 \
  31:                 --enable-all-optimizations \
  32:                 --enable-cpu-level=6 \
  33:                 --enable-x86-64 \
  34:                 --enable-vmx=2 \
  35:                 --enable-pci \
  36:                 --enable-clgd54xx \
  37:                 --enable-voodoo \
  38:                 --enable-usb \
  39:                 --enable-usb-ohci \
  40:                 --enable-es1370 \
  41:                 --enable-e1000 \
  42:                 --enable-show-ips \
  43:         --enable-debugger \
  44:         --enable-disasm
  45:                 ${CONFIGURE_ARGS}
  46:     ;;
  47:  
  48:   plugins)
  49:     #######################################################################
  50:     # configuration 2 for release binary RPMs
  51:     # Include plugins, every possible gui.
  52:     #######################################################################
  53:     ./configure --enable-sb16 \
  54:                 --enable-ne2000 \
  55:                 --enable-all-optimizations \
  56:                 --enable-cpu-level=6 \
  57:                 --enable-x86-64 \
  58:                 --enable-vmx=2 \
  59:                 --enable-pci \
  60:                 --enable-clgd54xx \
  61:                 --enable-voodoo \
  62:                 --enable-usb \
  63:                 --enable-usb-ohci \
  64:                 --enable-usb-xhci \
  65:                 --enable-es1370 \
  66:                 --enable-e1000 \
  67:                 --enable-plugins \
  68:                 --enable-show-ips \
  69:                 --with-all-libs \
  70:         --enable-debugger \
  71:         --enable-disasm
  72:                 ${CONFIGURE_ARGS}
  73:     ;;
  74:  
  75: esac

修改完後,執行sudo bash .conf.linux腳本進行配置svn

安裝oop

   1: sudo make
   2: sudo make install

http://bochs.sourceforge.net/diskimages.html,下載一個已經配置好的img.ui

   1: sudo wget http://bochs.sourceforge.net/guestos/dlxlinux4.tar.gz
   2: sudo gzip -d dlxlinux4.tar.gz
   3: sudo tar -xvf dlxlinux4.tar
   4: cd dlxlinux4
   5: bochs -q -f bochsrc.txt

就進入了調試狀態

   1: daniel@ubuntu:~/linux-3.0/bochs/dlxlinux$ bochs -q -f dlxlinux.bxrc 
   2: ========================================================================
   3:                      Bochs x86 Emulator 2.6.2.svn
   4:               Built from SVN snapshot after release 2.6.2
   5:                   Compiled on Feb 14 2014 at 01:21:35
   6: ========================================================================
   7: 00000000000i[      ] LTDL_LIBRARY_PATH not set. using compile time default '/usr/local/lib/bochs/plugins'
   8: 00000000000i[      ] BXSHARE not set. using compile time default '/usr/local/share/bochs'
   9: 00000000000i[      ] lt_dlhandle is 0xa956340
  10: 00000000000i[PLUGIN] loaded plugin libbx_unmapped.so
  11: 00000000000i[      ] lt_dlhandle is 0xa9569d0
  12: 00000000000i[PLUGIN] loaded plugin libbx_biosdev.so
  13: 00000000000i[      ] lt_dlhandle is 0xa956fb0
  14: 00000000000i[PLUGIN] loaded plugin libbx_speaker.so
  15: 00000000000i[      ] lt_dlhandle is 0xa9577d8
  16: 00000000000i[PLUGIN] loaded plugin libbx_extfpuirq.so
  17: 00000000000i[      ] lt_dlhandle is 0xa957d28
  18: 00000000000i[PLUGIN] loaded plugin libbx_parallel.so
  19: 00000000000i[      ] lt_dlhandle is 0xa959160
  20: 00000000000i[PLUGIN] loaded plugin libbx_serial.so
  21: 00000000000i[      ] lt_dlhandle is 0xa95c400
  22: 00000000000i[PLUGIN] loaded plugin libbx_gameport.so
  23: 00000000000i[      ] lt_dlhandle is 0xa95c9b8
  24: 00000000000i[PLUGIN] loaded plugin libbx_iodebug.so
  25: 00000000000i[      ] reading configuration from dlxlinux.bxrc
  26: 00000000000i[      ] lt_dlhandle is 0xa95cf28
  27: 00000000000i[PLUGIN] loaded plugin libbx_x.so
  28: 00000000000i[      ] installing x module as the Bochs GUI
  29: 00000000000i[      ] using log file bochsout.txt
  30: Next at t=0
  31: (0) [0x0000fffffff0] f000:fff0 (unk. ctxt): jmpf 0xf000:e05b          ; ea5be000f0
  32: <bochs:1> ^C

按下Ctrl+Z能夠退出調試程序

 

關於調試指令,能夠參見http://bochs.sourceforge.net/cgi-bin/topper.pl?name=New+Bochs+Documentation&url=http://bochs.sourceforge.net/doc/docbook/user/index.html

 

dlxlinux內核有一個缺點,就是內核太老了,是1.3版本。

在Bochs img列表中,還有一項

Linux kernel image for x86-64 from Andi Kleen at SuSE, which can be used as a boot floppy. Here is the System.map file for it, which can be useful for debugging.

這裏只提供了一個linux內核映像,是bzImage格式,做爲floppy掛載能夠啓動內核,可是提示找不到根文件系統。所以,咱們須要本身搞定根文件系統。

不想從頭作一個根文件系統,就能夠將dlxlinux的拷貝過來用。

怎樣將root.img掛載到當前的目錄中?

由於root.img裏面包含着MBR以及第一個分區,並且第一個分區並非緊跟在MBR後面,怎麼可以知道第一個分區的位置呢?

能夠查看MBR中的分區表記錄

 

   1: dlxlinux $ hd root.img -s 446 | head
   2: 000001be  00 01 01 00 83 03 51 31 
11 00 00 00 37 51 00 00
  |......Q1....7Q..|
   3: 000001ce  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
   4: *
   5: 000001fe  55 aa 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |U...............|
   6: 0000020e  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
   7: *
   8: 000025fe  00 00 30 0a 00 00 9b 28  00 00 07 02 00 00 a6 1c  |..0....(........|
   9: 0000260e  00 00 b1 07 00 00 01 00  00 00 00 00 00 00 00 00  |................|
  10: 0000261e  00 00 00 20 00 00 00 20  00 00 18 05 00 00 b4 7a  |... ... .......z|
  11: 0000262e  ff 52 79 17 ff 52 1e 00  14 00 53 ef 00 00 01 00  |.Ry..R....S.....|

紅色部分分別表明第一個分區的起始扇區號爲0x00000011,扇區個數爲0x00005137。

所以, 咱們能夠用下面命令將root.img掛載起來。

   1: sudo mkdir root
   2: sudo mount -o loop,offset=8704 root.img ./root

其中,8704=0x11 * 0x200

本身建立一個img,而且將一個文件系統塞進去,而且製做分區表。

http://archive09.linux.com/forums/topic/1519

http://thestarman.pcministry.com/asm/mbr/PartTables.htm

http://aneeska.com/2011/04/07/how-to-create-a-partition-in-an-image-file/

   1: losetup /dev/loop0 root.img
   2: mkfs.ext3 /dev/loop0 
   3: mount /dev/loop0 ./root
   4: # copy files to ./root
   5: umount ./root 
   6: losetup -d /dev/loop0

給img擴容

   1: sudo dd if=/dev/zero of=bigroot.img bs=1024 seek=10404 count=5120
   1: fdisk -u bigroot.img -c=dos

打造一個本身的根文件系統,使用指定的Linux內核文件,再加上Grub用於啓動。

參考:http://blog.csdn.net/deansrk/article/details/6661293

http://blog.chinaunix.net/uid-26207112-id-3332621.html

可是沒法進入

linux

將linux.vdi文件做成linux.img文件,用Bochs進行調試,而且參考System.map中給出的線性地址進行斷點設置,發現有執行到/sbin/init初始化任務

   1: do_execve
   2: do_execve_common
   3: open_execve
   4: do_filp_open
   5: path_openat

返回了-1(#define    EPERM         1    /* Operation not permitted */)

即操做不容許錯誤。

   1: static struct file *path_openat(int dfd, const char *pathname,
   2:         struct nameidata *nd, const struct open_flags *op, int flags)
   3: {
   4:  
   5:     current->total_link_count = 0;
   6:     error = link_path_walk(pathname, nd);
   7:     if (unlikely(error))
   8:         goto out_filp;
   9:  
  10: }
相關文章
相關標籤/搜索