分享

实现操作系统之环境搭建 | Bochs 2.6.7

 herowuking 2015-03-31

记得很久以前,就开始准备实现一个自己操作系统,找了一本《Orange’s 一个操作系统的实现》来看。满怀期待的进入最开始章节,环境搭建篇,足足让我整了一个通宵还没整出Hello World,后来就忘记了要写操作系统这件事了。现在拿起这本书,希望坚持做下去,并把我自己的编译器放上去运行。同时我也会在每个阶段记录在我的博客上。

环境搭建在书上有详细的介绍,但是这本书已年代久远,各种工具也更新换代多次,使用方法略有区别,但大致相同。我把过程在此记录,希望能帮助到有需要的人,以不至于被第一步就困难到。

我的运行环境是Windows8,Linux下我也会简略介绍。

准备阶段

安装NASM

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

dd命令工具

Windows下有dd for Windows的工具,下载地址http://www./download,找到dd-*(版本号).zip,下载解压即可使用。

 Bochs安装

Bochs主页http://bochs./,可直接安装。

配置环境变量

将三个软件的安装位置加入环境变量中,相信安装过软件的都知道如何设置,这里就不详细说明了。

测试软件

在cmd下输入

1
2
3
nasm -version
dd
bochs

如果指令都正常,我们的准备工作就完成了,若发生错误,有可能是环境变量设置问题,可重新检查一遍。

操作阶段

汇编boot.asm

1
nasm boot.asm -oboot.bin

注意路径不要搞错。

生成软盘映像

这里使用bximage,和书中的操作略有不同,注意阅读一下指令的输出。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
d:\oranges\Bochs-2.6.7>bximage
========================================================================
                                bximage
  Disk Image Creation / Conversion / Resize and Commit Tool for Bochs
         $Id: bximage.cc 12364 2014-06-07 07:32:06Z vruppert $
========================================================================
1. Create new floppy or hard disk image
2. Convert hard disk image to other format (mode)
3. Resize hard disk image
4. Commit 'undoable' redolog to base image
5. Disk image info
0. Quit
Please choose one [0] 1   //这里需要选择1,生成新的软盘或硬盘
Create image
Do you want to create a floppy disk image or a hard disk image?
Please type hd or fd. [hd] fd     //选fd为软盘
Choose the size of floppy disk image to create, in megabytes.
Please type 160k, 180k, 320k, 360k, 720k, 1.2M, 1.44M, 1.68M, 1.72M, or 2.88M.
<span style="text-decoration: underline;"> [1.44M]     //回车即默认</span>
What should be the name of the image?
[a.img]     //回车即默认
Creating floppy image 'a.img' with 2880 sectors
The following line should appear in your bochsrc:
  floppya: image="a.img", status=inserted
(The line is stored in your windows clipboard, use CTRL-V to paste)
Press any key to continue

最终a.img生成在cmd的当前目录下,请注意目录。

写入引导

我在这一步遇到了问题,试了两次都没写入,后来分析了一下找出了问题所在。

书上的命令为

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

首先要注意这里的if是指输入文件,即汇编后的生成文件。a.img是软盘映像,这里一定要看看这两个文件是否在同一路径和在cmd当前目录中,否则就要加上完整的路径。其次,当输入完指令后,输出为

1
2
3
4
5
6
7
8
9
10
11
12
13
14
d:\oranges\code>dd if=boot.bin of=a.img bs=512 count=1 conv=notrunc
rawwrite dd for windows version 0.5.
Written by John Newbigin <jn@it.swin.edu.au>
This program is covered by the GPL.  See copying.txt for details
Unknown command conv=notrunc
dd [bs=SIZE] [count=BLOCKS] [if=FILE] [of=FILE] [seek=BLOCKS] [skip=BLOCKS] [--s
ize] [--list] [--progress]
SIZE and BLOCKS may have one of the following suffix:
k = 1024
M = 1048576
G = 1073741824
default block size (bs) is 512 bytes
skip specifies the starting offset of the input file (if)
seek specifies the starting offset of the output file (of)

下划线表示没有这个指令,我猜测dd工具已经更新掉了这个命令,所以去掉即可。

配置bochsrc.bxrc文件

我的配置文件是

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
##################################  
# configure filefor Bochs in win7  
##################################  
  
# how much memorythe emulated machine will have  
megs: 32  
  
# filename of ROMimages  
romimage:file=d:/oranges/Bochs-2.6.7/BIOS-bochs-latest  
vgaromimage:file=d:/oranges/Bochs-2.6.7/VGABIOS-lgpl-latest  
  
# what disk imagewill be used  
floppya:image="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=d:/oranges/Bochs-2.6.7/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

注意改成自己的路径即可。

HELLO WORLD

双击bochsrc.boxrc。360软件小助手截图20141126024515

搞定!!!

 

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多