﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-斜树的空间-随笔分类-自己动手些操作系统</title><link>http://www.cppblog.com/Viking/category/15188.html</link><description>集中精力，放弃一切的去做一件事情，只要尽力了，即使失败了，你也不会后悔！</description><language>zh-cn</language><lastBuildDate>Sun, 21 Nov 2010 09:27:44 GMT</lastBuildDate><pubDate>Sun, 21 Nov 2010 09:27:44 GMT</pubDate><ttl>60</ttl><item><title>麒麟操作系统内核同其他操作系统内核的相似性分析(按ctrl + a 阅读)</title><link>http://www.cppblog.com/Viking/archive/2010/11/17/133920.html</link><dc:creator>张贵川</dc:creator><author>张贵川</author><pubDate>Wed, 17 Nov 2010 13:48:00 GMT</pubDate><guid>http://www.cppblog.com/Viking/archive/2010/11/17/133920.html</guid><wfw:comment>http://www.cppblog.com/Viking/comments/133920.html</wfw:comment><comments>http://www.cppblog.com/Viking/archive/2010/11/17/133920.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/Viking/comments/commentRss/133920.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/Viking/services/trackbacks/133920.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 麒麟操作系统内核同其他操作系统内核的相似性分析                          &nbsp; &nbsp;                        Copyright (c)&nbsp;2006            &nbsp;Dancefire (dancefire#gmail).                        Permiss...&nbsp;&nbsp;<a href='http://www.cppblog.com/Viking/archive/2010/11/17/133920.html'>阅读全文</a><img src ="http://www.cppblog.com/Viking/aggbug/133920.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/Viking/" target="_blank">张贵川</a> 2010-11-17 21:48 <a href="http://www.cppblog.com/Viking/archive/2010/11/17/133920.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>如何在Linux上使用Bochs[转]</title><link>http://www.cppblog.com/Viking/archive/2010/10/16/130150.html</link><dc:creator>张贵川</dc:creator><author>张贵川</author><pubDate>Sat, 16 Oct 2010 10:12:00 GMT</pubDate><guid>http://www.cppblog.com/Viking/archive/2010/10/16/130150.html</guid><wfw:comment>http://www.cppblog.com/Viking/comments/130150.html</wfw:comment><comments>http://www.cppblog.com/Viking/archive/2010/10/16/130150.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/Viking/comments/commentRss/130150.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/Viking/services/trackbacks/130150.html</trackback:ping><description><![CDATA[<div id="blog_text" class="cnt">
<div align="right">作者：王聪</div>
<h2>
<div align="center">引言</div>
</h2>
<p>&nbsp;&nbsp;&nbsp;&nbsp; 最近在做操作系统方面的研究，不得不去下一个虚拟机
来用。由于我不使用Windows，所以选择很少了。因为在Linux上，差不多就只有两款好的
虚拟机——Bochs和Qemu。这两个之中，Bochs是用C++编写，能在很多平台上使用，而且不论什么平台，
它都不倚赖主机的指令系统，总是模拟x86。所以我选择了Bochs。但是，我惊讶地发现
关于如何在Linux上使用Bochs的资料很少。Bochs自带的文档中讲得也不很明确，而且还 是英文的。所以我写了这篇文章。</p>
<h2>
<div align="center">安装</div>
</h2>
<p>&nbsp;&nbsp;&nbsp;&nbsp; 到Bochs的主页： <a href="http://bochs.sourceforge.net/">http://bochs.sourceforge.net</a>
上下载最新的Bochs RPM安装包。（写这篇文章时，最新的版本是2.2.1。）以root的身份安装：</p>
<blockquote>#rpm -ivh bochs-2.2.1-1.i586.rpm</blockquote>
其实RPM安装包给你装上了四个新程序：bochs，bochs-dlx，bximage，bxcommit，
以及相关文档。安装完毕后，你可以先试试bochs-dlx，它是DLX Linux的一个demo。 <blockquote> $
bochs-dlx<br>
---------------------------------------------------------------<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DLX Linux Demo, for Bochs x86 Emulator<br>
---------------------------------------------------------------<br>
Checking for bochs binary...ok<br>
Checking for DLX linux directory...ok<br>
Checking for /usr/bin/gzip...ok<br>
Checking for /home/wangcong/.bochsdlx directory...ok<br>
Entering /home/wangcong/.bochsdlx<br>
Running bochs<br>
00000000000i[APIC?] local apic in  initializing<br>
========================================================================<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Bochs x86 Emulator 2.2.1<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Build from CVS snapshot on July 8, 2005<br>
========================================================================<br>
00000000000i[     ] LTDL_LIBRARY_PATH not set. using compile time
default '/usr/lib/bochs/plugins'<br>
00000000000i[     ] BXSHARE not set. using compile time default
'/usr/share/bochs'<br>
00000000000i[     ] reading configuration from bochsrc.txt<br>
00000000000i[     ] lt_dlhandle is 0x8bac490<br>
00000000000i[PLGIN] loaded plugin libbx_x.la<br>
00000000000i[     ] installing x module as the Bochs GUI<br>
00000000000i[     ] using log file bochsout.txt<br>
<br>
</blockquote> 马上，你就会看到一个X11窗口。<br>
<br>
<img src="http://www.wangcong.org/images/scrshot.jpg" height="476" width="728" border="0"><br>
<br>
显示的是VGA BIOS信息，然后是加载Linux的信息。以root身份登录，试试DLX Linux。安装成功。
<h2>
<div align="center">使用</div>
</h2>
<p>&nbsp;&nbsp;&nbsp;&nbsp; 下面是一些重要的文件： <br>
<br>
<table>
    <tbody>
        <tr>
            <td>/usr/bin/bochs</td>
            <td>Bochs启动程序</td>
        </tr>
        <tr>
            <td>/usr/bin/bximage</td>
            <td>Bochs带的制作磁盘镜像文件的工具</td>
        </tr>
        <tr>
            <td>/usr/bin/bxcommit</td>
            <td>把redolog放进flat磁盘镜像文件中去的交互工具</td>
        </tr>
        <tr>
            <td>/usr/share/doc/bochs/bochsrc-sample.txt</td>
            <td>Bochs配置文件的例子</td>
        </tr>
        <tr>
            <td>/usr/share/bochs/BIOS-bochs-*</td>
            <td>ROM BIOS镜像文件</td>
        </tr>
        <tr>
            <td>/usr/share/bochs/VGABIOS-*</td>
            <td>与VGA BIOS镜像文件相关的文件</td>
        </tr>
        <tr>
            <td>/usr/bin/bochs-dlx</td>
            <td>启动Bochs中DLX linux的程序</td>
        </tr>
        <tr>
            <td>/usr/share/bochs/dlxlinux/</td>
            <td>DLX Linux的目录，包含它的磁盘镜像文件和配置文件</td>
        </tr>
        <tr>
            <td>/usr/share/bochs/keymaps/*.map</td>
            <td>X11和SDL的keymap列表</td>
        </tr>
    </tbody>
</table>
<br>
&nbsp;&nbsp;&nbsp;&nbsp; 命令bohcs可以接受4个参数：-q　加载配置文件后跳过开始菜单；-f configfile
识别指定的配制文件；-n　不加载配置文件；-h 打印帮助信息；-qf configfile
相当于同时使用-q和-f两个选项。使用Bochs，你必须有一个配置文件，或者你通
过-f参数指定，或者让Bochs自己搜索。配置文件的作用是告诉Bochs到哪里寻找镜像 文件，模拟层如何工作等。Bochs搜索配置文件的顺序是：</p>
<ol type="1">
    <li>
    <p> </p>
    <br></li>
    <li>
    <p>
    <tt class="FILENAME">bochsrc</tt>  在当前目录中</p>
    </li>
    <li>
    <p> </p>
    <br></li>
    <li>
    <p>
    <tt class="FILENAME">.bochsrc</tt>  在用户的主目录中</p>
    </li>
    <li>
    <p>
    <tt class="FILENAME">bochsrc</tt>  在
    <tt class="FILENAME"> /etc</tt>
    目录中</p>
    </li>
</ol>
以dlx-linux的配置文件为例，讲一下如何定制你需要的配置文件。dlx-linux的
配置文件是/usr/share/doc/bochs目录中的bochsrc-sample.txt。它的内容 如下： <blockquote>
###############################################################<br>
# bochsrc.txt file for DLX Linux disk image.<br>
###############################################################<br>
<br>
# how much memory the emulated machine will have<br>
megs: 32<br>
<br>
# filename of ROM images<br>
romimage: file=$BXSHARE/BIOS-bochs-latest, address=0xf0000<br>
vgaromimage: file=$BXSHARE/VGABIOS-lgpl-latest<br>
<br>
# what disk images will be used <br>
floppya: 1_44=floppya.img, status=inserted<br>
floppyb: 1_44=floppyb.img, status=inserted<br>
<br>
# hard disk<br>
ata0: enabled=1, ioaddr1=0x1f0, ioaddr2=0x3f0, irq=14<br>
ata0-master: type=disk, path="hd10meg.img", cylinders=306, heads=4,
spt=17<br>
<br>
# choose the boot disk.<br>
boot: c<br>
<br>
# default config interface is textconfig.<br>
#config_interface: textconfig<br>
#config_interface: wx<br>
<br>
#display_library: x<br>
# other choices: win32 sdl wx carbon amigaos beos macintosh nogui rfb
term svga <br>
<br>
# where do we send log messages?<br>
log: bochsout.txt<br>
<br>
# disable the mouse, since DLX is text only<br>
mouse: enabled=0<br>
<br>
# enable key mapping, using US layout as default.<br>
#<br>
# NOTE: In Bochs 1.4, keyboard mapping is only 100% implemented on X
windows.<br>
# However, the key mapping tables are used in the paste function, so <br>
# in the DLX Linux example I'm enabling keyboard_mapping so that paste <br>
# will work.  Cut&amp;Paste is currently implemented on win32 and X
windows only.<br>
<br>
keyboard_mapping: enabled=1, map=$BXSHARE/keymaps/x11-pc-us.map<br>
#keyboard_mapping: enabled=1, map=$BXSHARE/keymaps/x11-pc-fr.map<br>
#keyboard_mapping: enabled=1, map=$BXSHARE/keymaps/x11-pc-de.map<br>
#keyboard_mapping: enabled=1, map=$BXSHARE/keymaps/x11-pc-es.map<br>
</blockquote>  以#开头的每一行都是注释。注释写得很明白。 <blockquote>megs: 32</blockquote>
指明想要模拟32M的内存。注意：后面的数字最大为2048，但是因为主机系统的限制，在 大多数系统上，Bochs甚至不能支持1024M。 <blockquote>romimage:
file=$BXSHARE/BIOS-bochs-latest, address=0xf0000</blockquote>
指明ROM的镜像文件在哪，开机时ROM BIOS被加载到哪里。$BXSHARE是环境变量，指明
Bochs的share目录，在Linux上为/usr/share/bochs。这一般不用改动。下面的vgaromimage 指明VGA
ROM的镜像文件位置。 <blockquote> floppya: 1_44=floppya.img, status=inserted<br>
floppyb: 1_44=floppyb.img, status=inserted </blockquote>
floppya是第一软驱，floppyb是第二软驱。后面标明的是软驱镜像文件的位置，软盘 是否插入。可以根据你的需要做适当的修改。 <blockquote>
ata0: enabled=1, ioaddr1=0x1f0, ioaddr2=0x3f0, irq=14<br>
ata0-master: type=disk, path="hd10meg.img", cylinders=306, heads=4,
spt=17<br>
</blockquote> 打开ata0通道，另外还有ata1，ata2，ata3。对于每一个通道，都必须指明两个IO地址和IRQ。
ata0是默认被打开的，它的ioaddr1=0x1f0, ioaddr2=0x3f0, irq=14。ata0-master
是主ata0通道，后面指明它附带的设备是硬盘，硬盘镜像文件路径，硬盘柱面数，磁头数等参数。 <blockquote>boot: c</blockquote>
指明启动次序，可以是cdrom，floppy，disk。不过由于历史的原因a和c也能被接受。 也可以这样来写： <blockquote>boot:
cdrom, floppy, disk</blockquote> <blockquote>mouse: enabled=0</blockquote>
指明鼠标是否可见。 <blockquote>keyboard_mapping: enabled=1,
map=$BXSHARE/keymaps/x11-pc-us.map</blockquote>
打开对虚拟US键盘的重映射，keymap必须被指明。<br>
&nbsp;&nbsp;&nbsp;&nbsp; 更多的配置文件选项说明见/usr/share/doc/bochs/user/bochsrc.html。
如何编写键盘的keymap列表见/usr/share/doc/bochs/user/keymap.html。
<h2>
<div align="center">制作磁盘镜像</div>
</h2>
<p>&nbsp;&nbsp;&nbsp;&nbsp; bximage是Bochs自带的制作磁盘镜像的工具，具有 良好的交互性，使用很方便。运行bximage，你会看到：</p>
<blockquote>
========================================================================<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bximage<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Disk Image Creation Tool for Bochs<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $Id: bximage.c,v 1.25.2.1 2005/07/06 20:40:00 vruppert Exp $<br>
========================================================================<br>
<br>
Do you want to create a floppy disk image or a hard disk image?<br>
Please type hd or fd. [hd]<br>
</blockquote> 询问我们是建立一个软盘镜像还是硬盘镜像，默认的是硬盘。我们直接按回车，选择硬盘 镜像。 <blockquote>
What kind of image should I create?<br>
Please type flat, sparse or growing. [flat]<br>
</blockquote> 我们想建立一个简单的镜像，选择默认的flat。回车。 <blockquote> Enter the hard
disk size in megabytes, between 1 and 32255<br>
[10]<br>
</blockquote> 想要多少Mbyte的大小？键入你想要的大小。 <blockquote> I will create a 'flat'
hard disk image with<br>
&nbsp;&nbsp; cyl=2<br>
&nbsp;&nbsp; heads=16<br>
&nbsp;&nbsp; sectors per track=63<br>
&nbsp;&nbsp; total sectors=2016<br>
&nbsp;&nbsp; total size=0.98 megabytes<br>
<br>
What should I name the image?<br>
[c.img]<br>
</blockquote> 在上一步中输入&#8220;1&#8221;后，显示相关的硬盘信息。询问想要什么镜像文件名字？默认的是 c.img。输入hd.img回车。 <blockquote>
Writing: [] Done.<br>
<br>
I wrote 1032192 bytes to hd.img.<br>
<br>
The following line should appear in your bochsrc:<br>
&nbsp;&nbsp; ata0-master: type=disk, path="hd.img", mode=flat, cylinders=2,
heads=16, spt=63 </blockquote> 建立完毕。然后你就可以使用这个镜像，用Bochs做实验了。  <br>
<p>&nbsp;&nbsp;&nbsp;&nbsp; 另外Bochs还有强大的调试功能，详细请参阅用户
手册第8章。Bochs主页上还有一些做好的系统镜像，比如：OpenBSD，FreeDOS等。 不妨<a href="http://bochs.sourceforge.net/diskimages.html">下载</a>一个来试试。
Bochs的确是一款优秀的工具，我推荐给每一位做操作系统研究的朋友。</p>
</div>
<br><img src ="http://www.cppblog.com/Viking/aggbug/130150.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/Viking/" target="_blank">张贵川</a> 2010-10-16 18:12 <a href="http://www.cppblog.com/Viking/archive/2010/10/16/130150.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>bochs和硬盘管理</title><link>http://www.cppblog.com/Viking/archive/2010/10/14/129926.html</link><dc:creator>张贵川</dc:creator><author>张贵川</author><pubDate>Thu, 14 Oct 2010 12:59:00 GMT</pubDate><guid>http://www.cppblog.com/Viking/archive/2010/10/14/129926.html</guid><wfw:comment>http://www.cppblog.com/Viking/comments/129926.html</wfw:comment><comments>http://www.cppblog.com/Viking/archive/2010/10/14/129926.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/Viking/comments/commentRss/129926.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/Viking/services/trackbacks/129926.html</trackback:ping><description><![CDATA[<meta http-equiv="content-type" content="text/html; charset=utf-8"><span  style="color: rgb(37, 76, 81); font-family: Arial; font-size: 12px; line-height: 18px; "><table style="table-layout: fixed; width: 900px; "><tbody><tr><td style="color: rgb(37, 76, 81); font-family: Arial; word-wrap: break-word; word-break: break-all; visibility: visible !important; zoom: 1 !important; filter: none; font-size: 12px; line-height: 18px; "><div id="blog_text" class="cnt" style="color: rgb(37, 76, 81); font-family: Arial; word-wrap: break-word; word-break: normal; visibility: visible !important; zoom: 1 !important; filter: none; font-size: 12px; line-height: 18px; overflow-x: hidden; overflow-y: hidden; position: static; "><div style="color: rgb(37, 76, 81); font-family: Arial; word-wrap: break-word; word-break: break-all; visibility: visible !important; zoom: 1 !important; filter: none; font-size: 16px; line-height: normal; text-decoration: none; ">实验一&nbsp;<br style="line-height: normal; ">目的：熟悉实验环境，认识Bochs虚拟机&nbsp;<br style="line-height: normal; ">内容：&nbsp;<br style="line-height: normal; ">1、下载并安装Bochs 2.3.7，官方网站&nbsp;<a href="http://bochs.sourceforge.net/" target="_blank" eventslistuid="e3" style="font-size: 12px; color: rgb(37, 76, 81); text-decoration: none; font-family: 'Courier New', Courier, monospace; line-height: normal; ">http://bochs.sourceforge.net/</a><wbr style="line-height: normal; ">&nbsp;<br style="line-height: normal; ">2、下载DOS 6.22安装光盘，参考地址&nbsp;<a href="http://www.grqhd.com/downloads/hdd/dos622cd.iso" target="_blank" eventslistuid="e4" style="font-size: 12px; color: rgb(37, 76, 81); text-decoration: none; font-family: 'Courier New', Courier, monospace; line-height: normal; ">http://www.grqhd.com/downloads/hdd/dos622cd.iso</a><wbr style="line-height: normal; ">&nbsp;<br style="line-height: normal; ">3、使用Bochs自带工具制作10M硬盘镜像若干、1.44M软盘镜像若干，备用。&nbsp;<br style="line-height: normal; ">4、练习修改Bochs配置文件，使用DOS 6.22安装光盘将DOS安装到硬盘和软盘。&nbsp;<br style="line-height: normal; ">5、练习修改配置文件，分别实现从光盘、硬盘或软盘启动。&nbsp;<br style="line-height: normal; "><br style="line-height: normal; ">实验二&nbsp;<br style="line-height: normal; ">目的：MBR的读写与分析&nbsp;<br style="line-height: normal; ">内容：&nbsp;<br style="line-height: normal; ">1、练习使用int 13功能获取安装了DOS 6.22系统的硬盘MBR、反汇编。&nbsp;<br style="line-height: normal; ">2、使用int 13功能将获取的MBR，写到空白的硬盘上。&nbsp;<br style="line-height: normal; ">3、修改MBR代码，并测试其工作流程。&nbsp;<br style="line-height: normal; "><br style="line-height: normal; ">实验三&nbsp;<br style="line-height: normal; ">目的：掌握分区表的数值意义&nbsp;<br style="line-height: normal; ">内容：&nbsp;<br style="line-height: normal; ">1、练习使用DOS 6.22自带的分区工具FDisk，把一个空白硬盘分区，观察MBR的变化。&nbsp;<br style="line-height: normal; ">2、使用FDisk把一个空白硬盘分一个主分区，自定义大小，其余分为扩展分区，扩展分区上分两个逻辑分区，自定义大小。&nbsp;<br style="line-height: normal; ">3、说明以上分区表的数值含义。&nbsp;<br style="line-height: normal; "><br style="line-height: normal; ">实验四&nbsp;<br style="line-height: normal; ">目的：DBR的读写与分析&nbsp;<br style="line-height: normal; ">内容：&nbsp;<br style="line-height: normal; ">1、获取正常DOS 6.22系统盘上的DBR，并反汇编、阅读。&nbsp;<br style="line-height: normal; ">2、比较空白硬盘经分区后，使用Format前后DBR的差别。&nbsp;<br style="line-height: normal; ">3、测试DBR的工作流程。&nbsp;<br style="line-height: normal; "><br style="line-height: normal; ">实验五&nbsp;<br style="line-height: normal; ">目的：掌握FAT原理&nbsp;<br style="line-height: normal; ">内容：&nbsp;<br style="line-height: normal; ">1、以FAT12为例，分析BPB以及FAT、根目录表。&nbsp;<br style="line-height: normal; ">2、利用以上原理，通过直接改写磁盘扇区的办法，在根目录下生成一个文本文件，并写入适当的内容。</div><div><br></div></div></td></tr></tbody></table></span>
<img src ="http://www.cppblog.com/Viking/aggbug/129926.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/Viking/" target="_blank">张贵川</a> 2010-10-14 20:59 <a href="http://www.cppblog.com/Viking/archive/2010/10/14/129926.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>