您的位置:首页 > 运维架构 > Linux

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

2012-11-10 02:00 423 查看

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上输出字符串而已...代码如下:

.globl begtext, begdata, begbss, endtext, enddata, endbss
.text
begtext:
.data
begdata:
.bss
begbss:
/* 这段代码主要是使用了bios设置的idr中断处理来完成的屏幕输出字符串.. */
.text
BOOTSEG = 0x07c0                /* bios最终会把执行全交给这个地址开始执行 */

entry start
start:
    go, BOOTSEG                 /* 通过jmpi设置段寄存器cs */
go: mov     ax, cs              /* 将ds,es都设为cs指向的段地址 */
    mov     ds, ax
    mov     es, ax
    mov     [msg1+17],ah
    mov     cx, #20             /* 共显示20个字符 */
    mov     dx, #0x1004         /* 屏幕第17行,第5列 */
    mov     bx, #0x000c         /* 字符显示为红色 */
    mov     bp, #msg1           /* 指定字符串的地址 */
    mov     ax, #0x1301         
    int     0x10                /* bios中断调用,功能号0x13,子功能0x01 */
loop1:      jmp loop1

msg1:        .ascii "Loading System ..."
            .byte    13,10

.org    510
            .word    0xAA55     /* 引导标志位 */

.text
endtext:
.data
enddata:
.bss
endbss:


3.2 Makefile

首先该代码为8086汇编,所以需要下载as86 ld86对该代码进行编译和链接...ubuntu11.04可以使用如下指令安装:

apt-get install bin86

Makefile 如下:

boot.img:boot
    dd bs=32 if=boot of=boot.img skip=1
boot:boot.o
    ld86 -0 -s -o boot boot.o
boot.o:boot.s
    as86 -0 -a -o boot.o boot.s
clean:
    rm -r boot boot.img *.o


3.3 bochs配置

这是我的bxrc文件,用于运行上面生成的image.

romimage: file=$BXSHARE/BIOS-bochs-latest 
cpu: model=core2_penryn_t9600, count=1, ips=50000000, reset_on_triple_fault=1, ignore_bad_msrs=1, msrs="msrs.def"
cpu: cpuid_limit_winnt=0
memory: guest=512, host=256
vgaromimage: file=$BXSHARE/VGABIOS-lgpl-latest
floppya: 1_44="boot.img", status=inserted
boot: a
floppy_bootsig_check: disabled=0
log: bochsout.txt
panic: action=ask
error: action=report
info: action=report
debug: action=ignore, pci=report # report BX_DEBUG from module 'pci'
debugger_log: -
parport1: enabled=1, file="parport.out"
mouse: enabled=0
private_colormap: enabled=0
pci: enabled=1, chipset=i440fx
megs: 16


3.4 执行效果

最终执行效果如下:



4:结束

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: