您的位置:首页 > 其它

Oragne's 一个操作系统的实现的环境搭建【ubutu+win7】

2013-07-31 10:34 603 查看
学习操作系统,一个很好的选择无疑是查看Linux内核源代码,然而这样的活对我来说难了点。但是如果能动手自己编写一个操作系统,边写操作系统边学习,也许这样应该能取得很不错的效果。故查阅各种资料,发现了这本不错的书《Orange's一个操作系统的实现》。

非常遗憾的是,这本书已经目前不再出版了,所以只能在淘宝上买了本复印版(不是不支持正版)!如果你看的是电子版,愁没有代码,请点击于老师关于这本书的项目主页:此书的官方网站

----------------------------------------------------------------------------------------------------------

在Orange‘s这本书中,有些人或许认为于老师给出的环境搭建有点模糊。在这里本文给出ubuntu和windows7两个详细配置,目前我用这个两个配置只跑了第一章的代码,现阶段还没出什么差错。

感谢博主快乐的霖霖的文章:orange's一个操作系统的实现之环境搭建

博主iefswang的文章:《orange'S一个操作系统的实现》
笔记。

一,Ubuntu12.04TLS下的环境搭建

1. 部分准备工作

bochs是由C++编写的,我们要安装相应的编译环境

sudo apt-get install build-essential

如果要图形界面:

安装bison:

有些文章说需要安装libgtk2.0-dev:

2.安装Bochs

先去Bochs的官网(或者直接去项目主页)下载目前最新源码包:bochs-2.6.2-tar.gz。

下载目录中会有很多老版本提供下载,不同版本会导致bochsrc的配置不同,也许正是因为这一点小问题会让我们纠结很久,所以请大家注意了。接下来:

tar xzvfbochs-2.6.2-tar.gz
cd bochs-2.6.2
./configure--enable-docbook= --enable-debugger --enable-disasm
sudo make
sudo make install


以前的老版本(2.3.5)在这个地方可能会出错,如果有问题请大家参考博主快乐霖霖的文章

3. Nasm安装

貌似Ubuntu12.04自带Nasm,你可以输入命令进行检测:

nasm -version
sudo apt-getinstall nasm


4. dd命令

因为Ubuntu12.04自带dd命令,我就拿来直接使用了。

5. bochsrc文件配置

通过前四步安装软件包,和确认部分命令,Ubuntu12.04下的环境已经配置已经基本完成。接下来的bochsrc文件的也是比较重要的,因为它直接关系到Bochs的运行。

在这里我给出三个版本的bochsrc的配置:于老师,博主快乐霖霖,我自己(bochs版本+Linux版本)

5.1 于老师:bochs-2.3.5 + Debian

于老师的配置是在Debian上弄的,在Ubuntu上可能行不通。

###############################################################
# Configurationfile for Bochs
###############################################################

# how much memorythe emulated machine will have
megs: 32

# filename of ROMimages
romimage:file=/usr/share/bochs/BIOS-bochs-latest
vgaromimage: file=/usr/share/vgabios/vgabios.bin

# what disk imageswill be used
floppya:1_44=a.img, status=inserted

# choose the bootdisk.
boot: floppy

# where do we sendlog messages?
log: bochsout.txt

# disable themouse
mouse: enabled=0

# enable keymapping, using US layout as default.
keyboard_mapping:enabled=1, map=/usr/share/bochs/keymaps/x11-pc-us.map


5.2 博主快乐霖霖:bochs-2.3.5 + Ubuntu8.10

###############################################################
# Configurationfile for Bochs
###############################################################

# how much memorythe emulated machine will have
megs: 32

# filename of ROMimages
romimage:file=/usr/local/share/bochs/BIOS-bochs-latest
vgaromimage:file=/usr/local/share/bochs/VGABIOS-lgpl-latest

# what disk imageswill be used
floppya:1_44=a.img, status=inserted

# choose the bootdisk.
boot: floppy

# where do we sendlog messages?
log: bochsout.txt

# disable themouse
mouse: enabled=0

# enable keymapping, using US layout as default.
keyboard_mapping:enabled=1, map=/usr/local/share/bochs/keymaps/x11-pc-us.map


与于老师的不同之处在于:romimage: file的文件位置,vgaromimage:file的文件位置,keyboard_mapping:map的文件位置。

5.3 我的配置:bochs-2.6.2 + Ubuntu12.04

############################
# Configurate filefor Bochs
############################

# how much memorythe emulated machine will have
megs: 32

# filename of ROMimages
romimage:file=/usr/local/share/bochs/BIOS-bochs-latest
vgaromimage:file=/usr/local/share/bochs/VGABIOS-lgpl-latest

# what disk imageswill be used
floppya:1_44=a.img, status=inserted

# choose the bootdisk.
boot: floppy

# where do we sendlog messages?
log: bochsout.txt

# disable themouse
mouse: enabled=0

# enable keymapping, using Us layout as default
keyboard:keymap=/usr/local/share/bochs/keymaps/x11-pc-us.map


与快乐霖霖的配置不同在于:因为bochs版本改动,导致键盘映射的关键词发生了变化,keyboard_mapping变成了kyboard,不需要启动标志,map变成keymap。

6 运行步骤演示

在指定目录中,编写好boot.asm后,就可以参考书上的一系列步骤了。

nasm boo.asm -o boot.bin


虚拟软驱(书本第一章可以不去实现,因为你没有真实的软驱,故于老师在第二章采用bochs组件中的虚拟软驱),因为bochs提供了功能,直接使用命令bximage(该步骤于老师书上有详细介绍)。

接下来dd命令的使用,把boot.bin写入虚拟软驱之a.img之中,命令:

dd if=boot.bin of=a.img bs=512 count=1 conv=notrunc


接着bochsrc文件的配置,详见步骤5。

最后就是运行bochs,输入完成后会有个选项,6进入bochs运行界面,命令:

bochs -f bochsrc









二,windows7下的环境配置

所有的安装目录最好为英文目录。

1 Nasm安装

Nasm的官方网站:http://sourceforge.net/projects/nasm/。下载完成直接安装,记住你的安装文件夹。

2 dd命令

Win7下直接下载该工具的windows版本dd for windows,下载地址为:http://www.chrysocome.net/dd,解压到你想放置的位置。

3 Bochs安装

去Bochs的官网:http://bochs.sourceforge.net/或者项目主页:http://bochs.sourceforge.net/cgi-bin/topper.pl?name=See+All+Releases&url=http://sourceforge.net/projects/bochs/files下载安装文件Bochs-2.6.2.exe。点击直接安装。

4 配置环境变量

在win7下,你可以切入到相应的安装目录下运行上面的程序,但是这样一来工作会繁琐很多。尤其是dd命令也不是那么好使。

为了方便起见,我把上述程序所在的安装文件夹配置到环境变量中,这样我们可以在dos下类似于linux一般直接敲命令执行相应的步骤。

环境变量配置:

计算机——右键属性——高级系统设置——环境变量——在系统变量中的变量栏中选择Path这个选项,点击编辑,找到Nasm,dd,Bochs相应的安装文件夹,插入到最后面,每插入一个切记输入英文分号;。

下面就是我的环境变量配置。

;G:\ProgramFiles\NASM;G:\Program Files\Bochs-2.6.2;G:\Program Files\dd-0.6beta3



切记要找准确安装目录,完成后可在dos下试试命令:

nasm -version
bochs
dd

5 bochsrc.bxrc的文件配置

在这里我只给出个人的配置:win7+Bochs-2.6.2

##################################
# configure filefor Bochs in win7
##################################

# how much memorythe emulated machine will have
megs: 32

# filename of ROMimages
romimage:file=G:/"Program Files"/Bochs-2.6.2/BIOS-bochs-latest
vgaromimage:file=G:/"Program Files"/Bochs-2.6.2/VGABIOS-lgpl-latest

# what disk imagewill be used
floppya:1_44=a.img, status=inserted
# floppya:1_44=floppyb.img, status=inserted

#hard disk
# ata0: enabled=1,ioaddr1=0x1fo, ioaddr2=0x3f0, irq=14
# ata0-master:type=disk, path="hd10meg.img", cylinders=306, heads=4, spt=17

# choose the bootdisk.
boot: a

# default configinterface is textconfig.
#config_interface:textconfig
#config_interface:w

#display_library:x
# other choices:win32 sdl wx carbon amigaos beos macintosh nogui rfb term

# where do we sendlog messages?
log: bochsout.txt

# disable themouse, since DLX is text only
mouse: enabled=0

# enable keymapping, using US layout as default.
#
# NOTE: In Bochs1.4, keyboard mapping is only 100% implemented on X windows.
# However, the keymapping tables are used in the paste function, so
# in the DLX Linuxexample I'm enabling keyboard_mapping so that paste
# will work.  Cut&Paste is currently implemented onwin32 and X windows only.

keyboard:keymap=G:/"Program Files"/Bochs-2.6.2/keymaps/x11-pc-us.map
#keyboard_mapping:enabled=1, map=$BXSHARE/keymaps/x11-pc-fr.map
#keyboard_mapping:enabled=1, map=$BXSHARE/keymaps/x11-pc-de.map
#keyboard_mapping:enabled=1, map=$BXSHARE/keymaps/x11-pc-es.ma


注意:如果你的安装文件目录中的文件夹含有空格,windows下典型的”Program Files”文件夹是有空格,在配置路径的时候,记得给含有空格项的文件夹加上双引号。

5 运行步骤演示

在指定文件夹中编辑好boo.asm文件,在dos下切换到该文件夹,首先执行nasm命令:

nasm boot.asm -oboot.bin

虚拟软驱(书本第一章可以不去实现,因为你没有真实的软驱,故于老师在第二章采用bochs组件中的虚拟软驱),因为bochs提供了功能,直接使用命令bximage(该步骤于老师书上有详细介绍)。

接下来dd命令的使用,把boot.bin写入虚拟软驱之a.img之中,命令:

dd if=boot.binof=a.img bs=512 count=1 conv=notrunc

上面的步骤与linux下完全相同。接着bochsrc.bxrc文件的配置,详见步骤4。

最后就是运行bochs,可以直接点击bohsrc.bxrc文件运行。





本文来自于duliang_wu的博客:http://blog.csdn.net/duliang_wu
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐