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

DEV环境切换memo:从win环境切换到linux(ubuntu11.10)

2013年02月14日 ⁄ 综合 ⁄ 共 3333字 ⁄ 字号 评论关闭

由于后续开发需要,准备将kernel开发的环境从win系统切换linux系统中,之前尝试过一次,不过卡在磁盘文件IO出错作罢,这次重新整了一遍,最后成功了,遂记录下,作为memo:


原开win开发环境:win7+bochs+vim7+hexviewer+vhdwriter,使用的虚拟磁盘为vhd格式,使用vhdwriter写nasm编译生成的bin文件


后续linux下的开发环境:ubuntu11.10+bochs+vim7+dd(文件io命令)+bximage(bochs内置虚拟io设备生成工具)。


memo:

首先使用nasm命令生成loader.bin以及kernel.bin

其次在工程路径下存放一个bochsrc配置文件:

文件格式:

romimage:file=$BXSHARE/BIOS-bochs-latest
vgaromimage:file=$BXSHARE/VGABIOS-lgpl-latest
#floppya: 1_44=DD.img, status=inserted
#ata0: enabled=1 #ioaddr1=0x1f0, ioaddr2=0x3f0, irq=14
#ata0-master: type=disk, path="DD.img", mode=flat, cylinders=20, heads=16, spt=63
ata0-master: type=disk, path="DD.img", mode=flat, cylinders=20, heads=16, spt=63

boot: disk
log:bochsout.log
mouse: enabled=0
keyboard_mapping: enabled=0, map=
megs:32


注意:其中的ata那行是灵活配置的,如果你是使用floppy作为介质,那么可以使用上面那个被注释的配置。我这里使用硬盘作为介质,所以需要配置ata。


接着使用bximage进行配置虚拟磁盘:

root@dev-linux:/home/devx/hack/DevOSV0.3# bximage
========================================================================
                                bximage
                  Disk Image Creation Tool for Bochs
        $Id: bximage.c,v 1.34 2009/04/14 09:45:22 sshwarts Exp $
========================================================================

Do you want to create a floppy disk image or a hard disk image?
Please type hd or fd. [hd] 

What kind of image should I create?
Please type flat, sparse or growing. [flat] 

Enter the hard disk size in megabytes, between 1 and 129023
[10] 

I will create a 'flat' hard disk image with
  cyl=20
  heads=16
  sectors per track=63
  total sectors=20160
  total size=9.84 megabytes

What should I name the image?
[c.img] DD.img

Writing: [] Done.

I wrote 10321920 bytes to DD.img.

The following line should appear in your bochsrc:
  ata0-master: type=disk, path="DD.img", mode=flat, cylinders=20, heads=16, spt=63
root@dev-linux:/home/devx/hack/DevOSV0.3# 


这里千万要注意这行东东:The following line should appear in your bochsrc:   ata0-master: type=disk, path="DD.img", mode=flat, cylinders=20, heads=16, spt=63,将前面标红的这句东东cp到之前的bochsrc配置文件中(ata那行),bochs会根据这个配置来进行磁盘io读写。


OK,到这里已经是成功的一半了,接下去所剩下需要做的就是将之前编译完成的bin文件写到bximage生成的虚拟磁盘文件中,这里最容易出错,必须注意:

正确的命令:

root@dev-linux:/home/devx/hack/DevOSV0.3# dd if=loader.bin of=DD.img bs=512 count=1 conv=notrunc
记录了1+0 的读入
记录了1+0 的写出
512字节(512 B)已复制,0.000724381 秒,707 kB/秒
root@dev-linux:/home/devx/hack/DevOSV0.3# dd if=kernel.bin of=DD.img seek=1 bs=512 conv=notrunc
记录了2051+1 的读入
记录了2051+1 的写出
1050132字节(1.1 MB)已复制,0.026953 秒,39.0 MB/

注意点1:count你如果清楚的话可以加,如果不知道,就不用加了,因为dd会自动计算出需要写入的扇区总数

2、必须使用conv=notrunc参数,该参数不会截断整个img文件,如果没有整个参数,原本bximage生成的文件会根据写入的bin文件大小给截断,那么就会出现运行过程中过程中各种异常,如bochs提示hd不是512的整数倍之类的错误。。。。。

3.seek的意思为从第几个扇区开始写,默认应该是从0扇区开始


ok,写入完成以后实际bochs进去看看运行效果:

注:该demo为含有bug的半成品,仅仅完成到了page模式下,kernel从虚拟地址空间1M移到高位虚拟地址空间上,仅仅完成这个映射:

root@dev-linux:/home/devx/hack/DevOSV0.3# bochs
========================================================================
                       Bochs x86 Emulator 2.4.5
              Build from CVS snapshot, on April 25, 2010
========================================================================
00000000000i[     ] reading configuration from bochsrc
------------------------------
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] 

抱歉!评论已关闭.