现在的位置: 首页 > 综合 > 正文

linux0.11 运行环境搭建以及调式–bochs (上)

2014年02月09日 ⁄ 综合 ⁄ 共 4461字 ⁄ 字号 评论关闭

linux0.11 运行环境搭建以及调式--bochs

1:下载及安装

1.1 工具下载

       首先,我们需要去官网下载该工具,这个工具有多个平台.下载地址如下:

            http://sourceforge.net/projects/bochs/ 

1.2 安装

这里我们选择windows平台Bochs-2.6.exe..安装过程很简单.一路next就行了..我把bochs安装在了E:\Program Files\Bochs-2.6路径下
安装完成之后会是这样的..

2:常用配置

2.1 配置文件

       在bochs中,可以设置一台虚拟pc,主要涉及的就是配置文件了.在windows中,可以直接通过双击配置文件就可以打开该配置的虚拟pc了..很方便.
       以后要修改pc配置,均以安装目录下的 bochsrc-sample.txt 文件作为参考.在上面进行修改.该文件为配置的例子..基本上只需要修改需要的部分,去掉不需要的部分,最后修改后缀为*.bxrc 就行了

2.1.1 megs

       megs用于模拟系统所含的内存容量.默认是32..例如
           megs: 16 修改为16M

2.1.2 floppya

       floppya 用于模拟一个软盘.最后a表示第一个软盘.当然b就是第二个软盘了..若是想用floppya引导.那就得给软件指定image文件.方法如下:
           floppya: 1_44="boot.img", status=insertedshatus=inserted表示已插入

2.1.3 ata0 ata1 ata 2 ata3

       这四个参数用于指定系统模拟ata通道.最多4个..例如:
           #   ata0: enabled=1, ioaddr1=0x1f0,  ioaddr2=0x3f0,  irq=14
           #   ata1: enabled=1, ioaddr1=0x170, ioaddr2=0x370, irq=15
           #   ata2: enabled=1, ioaddr1=0x1e8, ioaddr2=0x3e0, irq=11
           #   ata3: enabled=1, ioaddr1=0x168, ioaddr2=0x360, irq=9

2.1.4 ata0-master

       ata0-master用于模拟系统中第一个ata通道上连接的第一个ata设备,如硬盘,CDROM等,ata0-slave指明第一个通道上链接的第二个ata设备,如下:
          #   ata0-master: type=disk, mode=flat, path=10M.sample,   cylinders=306,   heads=4, spt=17
          #   ata0-slave:    type=disk, mode=flat, path=20M.sample,   cylinders=615,   heads=4, spt=17
          #   ata1-master: type=disk, mode=flat, path=30M.sample,   cylinders=615,   heads=6, spt=17
          #   ata1-slave:    type=disk, mode=flat, path=46M.sample,   cylinders=940,   heads=6, spt=17
          #   ata2-master: type=disk, mode=flat, path=62M.sample,   cylinders=940,   heads=8, spt=17
          #   ata2-slave:    type=disk, mode=flat, path=112M.sample, cylinders=900,   heads=15, spt=17
          #   ata3-master: type=disk, mode=flat, path=483M.sample, cylinders=1024,  heads=15, spt=63
          #   ata3-slave:    type=cdrom, path=iso.sample, status=inserted

2.1.5 boot

       指定虚拟系统启动引导的设备.由硬盘,软件,或者磁盘符号.如:
          #   boot: floppy
          #   boot: cdrom, disk
          #   boot: network, disk
          #   boot: cdrom, floppy, disk

2.1.6 ips

       表示虚拟系统每秒钟处理的指令条数,该值跟CPU有关..如下(此处为mipsms为单位):
          #  2.4.6 3.4Ghz Intel Core i7 2600 with Win7x64/g++ 4.5.2 85 to 95 Mips
          #  2.3.7 3.2Ghz Intel Core 2 Q9770 with WinXP/g++ 3.4     50 to 55 Mips
          #  2.3.7 2.6Ghz Intel Core 2 Duo with WinXP/g++ 3.4         38 to 43 Mips
          #  2.2.6 2.6Ghz Intel Core 2 Duo with WinXP/g++ 3.4         21 to 25 Mips
          #  2.2.6 2.1Ghz Athlon XP with Linux 2.6/g++ 3.4              12 to 15 Mips

2.1.7 log

       执行日志.bochs输出一些日志信息,比如执行不正确.错误定位非常实用..如下:
          #   log: ./bochs.out

3:LoadSystem...运行

3.1 boot.s代码

       首先这里由于刚刚开始,我提供了一段很简单的程序,让大家使用下工具..以后我们会大量依赖该工具,来编译调试等操作...这代码仅仅通过bios处理函数,在vga上输出字符串而已...代码如下:
  1. .globl begtext, begdata, begbss, endtext, enddata, endbss  
  2. .text  
  3. begtext:  
  4. .data  
  5. begdata:  
  6. .bss  
  7. begbss:  
  8. /* 这段代码主要是使用了bios设置的idr中断处理来完成的屏幕输出字符串.. */  
  9. .text  
  10. BOOTSEG = 0x07c0                /* bios最终会把执行全交给这个地址开始执行 */  
  11.   
  12. entry start  
  13. start:  
  14.     go, BOOTSEG                 /* 通过jmpi设置段寄存器cs */  
  15. go: mov     ax, cs              /* 将ds,es都设为cs指向的段地址 */  
  16.     mov     ds, ax  
  17.     mov     es, ax  
  18.     mov     [msg1+17],ah  
  19.     mov     cx, #20             /* 共显示20个字符 */  
  20.     mov     dx, #0x1004         /* 屏幕第17行,第5列 */  
  21.     mov     bx, #0x000c         /* 字符显示为红色 */  
  22.     mov     bp, #msg1           /* 指定字符串的地址 */  
  23.     mov     ax, #0x1301           
  24.     int     0x10                /* bios中断调用,功能号0x13,子功能0x01 */  
  25. loop1:      jmp loop1  
  26.   
  27. msg1:        .ascii "Loading System ..."  
  28.             .byte    13,10  
  29.   
  30. .org    510  
  31.             .word    0xAA55     /* 引导标志位 */  
  32.   
  33. .text  
  34. endtext:  
  35. .data  
  36. enddata:  
  37. .bss  
  38. endbss:  

3.2 Makefile

        首先该代码为8086汇编,所以需要下载as86 ld86对该代码进行编译和链接...ubuntu11.04可以使用如下指令安装:
            apt-get install bin86
        Makefile 如下:
  1. boot.img:boot  
  2.     dd bs=32 if=boot of=boot.img skip=1  
  3. boot:boot.o  
  4.     ld86 -0 -s -o boot boot.o  
  5. boot.o:boot.s  
  6.     as86 -0 -a -o boot.o boot.s  
  7. clean:  
  8.     rm -r boot boot.img *.o  

3.3 bochs配置

        这是我的bxrc文件,用于运行上面生成的image.
  1. romimage: file=$BXSHARE/BIOS-bochs-latest   
  2. cpu: model=core2_penryn_t9600, count=1, ips=50000000, reset_on_triple_fault=1, ignore_bad_msrs=1, msrs="msrs.def"  
  3. cpu: cpuid_limit_winnt=0  
  4. memory: guest=512, host=256  
  5. vgaromimage: file=$BXSHARE/VGABIOS-lgpl-latest  
  6. floppya: 1_44="boot.img", status=inserted  
  7. boot: a  
  8. floppy_bootsig_check: disabled=0  
  9. log: bochsout.txt  
  10. panic: action=ask  
  11. error: action=report  
  12. info: action=report  
  13. debug: action=ignore, pci=report # report BX_DEBUG from module 'pci'  
  14. debugger_log: -  
  15. parport1: enabled=1, file="parport.out"  
  16. mouse: enabled=0  
  17. private_colormap: enabled=0  
  18. pci: enabled=1, chipset=i440fx  
  19. megs: 16  

3.4 执行效果

       最终执行效果如下:

4:结束

原文见:http://blog.csdn.net/yyttiao/article/details/8168301#

抱歉!评论已关闭.