(第一、二章)安装nasm,bochs并运行helloworld

1、安装nasm和vgabios:[hadoop@sam1 /]$ su root
Password:
# yum install nasm
...# yum install vgabios
...

注意:bochs需要依赖vgabios安装的东西/usr/share/vgabios/VGABIOS-lgpl-latest.bin,所以vgabios需要先安装!

2、安装可调试版bochs(从源代码安装):

[color=red]注意:我先开始尝试安装Bochs 2.6等新版本都会出问题,最后还是安装了书上提到的bochs 2.3.5,configure/make/make install就一切正常了。[/color]

1)到bochs官方主页http://bochs.sourceforge.net/ ,有个Older News条目,进入当前最新版本Bochs 2.4.6
下载源代码包bochs-2.4.6.tar.gz

2)
tar vxzf bochs-2.4.6.tar.gz -->解压
cd bochs-2.4.6
./configure --enable-debugger --enable-disasm -->开启调试和反汇编功能
make
make install -->出现make: *** [install_bin] Error 1
(解决方法:命令前加上sudo就行,就是sudo make install)

2、制作引导扇区boot.asm:

1)桌面上(/home/hadoop/Desktop)新建OSImpl文件夹,在OSImpl下新建文件boot.asm,其内容如下

org 07c00h

mov ax,cs

mov ds,ax

mov es,ax

call DispStr

jmp $

DispStr:

mov ax, BootMessage

mov bp, ax

mov cx, 16

mov ax, 01301h

mov bx, 000ch

mov dl, 0 int 10h

ret

BootMessage: db "Hello, OS world!"

times 510-($-$$) db 0

dw 0xaa55

2)汇编boot.asm文件

[hadoop@sam1 OSImpl]$ pwd
/home/hadoop/Desktop/OSImpl
[hadoop@sam1 OSImpl]$ ls
bochs-2.4.6 boot.asm
[hadoop@sam1 OSImpl]$ nasm boot.asm -o boot.bin
[hadoop@sam1 OSImpl]$ ls
bochs-2.4.6 boot.asm boot.bin

3、创建软盘镜像文件a.img,把boot.bin逐字节拷贝进去
[hadoop@sam1 OSImpl]$ cd bochs-2.4.6/
[hadoop@sam1 bochs-2.4.6]$ ./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] fd

Choose the size of floppy disk image to create, in megabytes.
Please type 0.16, 0.18, 0.32, 0.36, 0.72, 1.2, 1.44, 1.68, 1.72, or 2.88.
[1.44]
I will create a floppy image with
cyl=80
heads=2
sectors per track=18
total sectors=2880
total bytes=1474560

What should I name the image?
[a.img]

Writing: [] Done.

I wrote 1474560 bytes to a.img.

The following line should appear in your bochsrc:
floppya: image="a.img", status=inserted

[hadoop@sam1 bochs-2.4.6]$ dd if=../boot.bin of=./a.img bs=512 count=1 conv=notrunc
-->虚拟机中需要指定conv这项,真实的机器中软盘不会被截断
1+0 records in
1+0 records out
512 bytes (512 B) copied, 6.3313e-05 s, 8.1 MB/s

4、创建配置文件.bochsrc,修改相关配置

如果使用yum install vgabios bochs bochs-x bximage 方式安装bochs,bochsrc-sample.txt作为配置文件的模板会被安装[hadoop@sam1 OSImpl]$ rpm -ql bochs | grep bochsrc-sample.txt


我这里用源代码包安装的,按照《Orange'S 一个操作系统的实现》P11配置即可:

[hadoop@sam1 bochs-2.4.6]$ gedit .bochsrc -->在工程文件夹下创建.bochsrc
####################################.bochsrc-start###################################

megs:32
romimage:file=/usr/share/bochs/BIOS-bochs-latest


#书上使用这个: vgaromimage:file=/usr/share/vgabios/vgabios.bin
#但通过ls -l /usr/share/vgabios/vgabios.bin发现并不存在,换成/usr/share/vgabios/VGABIOS-lgpl-latest.bin即可


vgaromimage:file=/usr/share/vgabios/VGABIOS-lgpl-latest.bin

floppya: 1_44=a.img, status=inserted

boot:floppy

log:bochsout.txt
#######################################.bochsrc-end#################################

5、启动bochs,运行Hello,OS world示例

[hadoop@sam1 bochs-2.4.6]$ ./bochs
========================================================================
Bochs x86 Emulator 2.4.6
Build from CVS snapshot, on February 22, 2011
Compiled at May 19 2011, 22:34:01
========================================================================
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] 2
00000000000i[ ] Screen mode changed to none

What is the configuration file name?
To cancel, type 'none'. [.bochsrc]
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]

*********************************************************************************
00000000000i[ ] installing x module as the Bochs GUI
00000000000i[ ] using log file bochsout.txt
Next at t=0
(0) [0x00000000fffffff0] f000:fff0 (unk. ctxt): jmp far f000:e05b ; ea5be000f0
<bochs:1> b 0x7c00
<bochs:2> c
(0) Breakpoint 1, 0x00007c00 in ?? ()
Next at t=12943100
(0) [0x0000000000007c00] 0000:7c00 (unk. ctxt): mov ax, cs ; 8cc8

<bochs:3> info cpu
eax: 0x0000aa55 43605
ecx: 0x00090000 589824
edx: 0x00000000 0
ebx: 0x00000000 0
esp: 0x0000ffd6 65494
ebp: 0x00000000 0
esi: 0x000e34e0 931040
edi: 0x0000ffac 65452
eip: 0x00007c00
eflags 0x00000082: id vip vif ac vm rf nt IOPL=0 of df if tf SF zf af pf cf
status word: 0x0000: b c3 TOS0 c2 c1 c0 es sf pe ue oe ze de ie
control word: 0x0040: inf RC_NEAREST PC_32 pm um om zm dm im
tag word: 0x5555
operand: 0x0000
fip: 0x00000000
fcs: 0x0000
fdp: 0x00000000
fds: 0x0000
=>FP0 ST0(0): raw 0x0000:0000000000000000 (0.0000000000) (ZERO)
FP1 ST1(0): raw 0x0000:0000000000000000 (0.0000000000) (ZERO)
FP2 ST2(0): raw 0x0000:0000000000000000 (0.0000000000) (ZERO)
FP3 ST3(0): raw 0x0000:0000000000000000 (0.0000000000) (ZERO)
FP4 ST4(0): raw 0x0000:0000000000000000 (0.0000000000) (ZERO)
FP5 ST5(0): raw 0x0000:0000000000000000 (0.0000000000) (ZERO)
FP6 ST6(0): raw 0x0000:0000000000000000 (0.0000000000) (ZERO)
FP7 ST7(0): raw 0x0000:0000000000000000 (0.0000000000) (ZERO)
MXCSR: 0x00001f80: ule fuz RC:0 PM UM OM ZM DM IM daz pe ue oe ze de ie
XMM[00]: 00000000:00000000:00000000:00000000
XMM[01]: 00000000:00000000:00000000:00000000
XMM[02]: 00000000:00000000:00000000:00000000
XMM[03]: 00000000:00000000:00000000:00000000
XMM[04]: 00000000:00000000:00000000:00000000
XMM[05]: 00000000:00000000:00000000:00000000
XMM[06]: 00000000:00000000:00000000:00000000
XMM[07]: 00000000:00000000:00000000:00000000

<bochs:4> x /64xb 0x7c00
[bochs]:
0x00007c00 <bogus+ 0>: 0x8c 0xc8 0x8e 0xd8 0x8e 0xc0 0xe8 0x02
0x00007c08 <bogus+ 8>: 0x00 0xeb 0xfe 0xb8 0x1e 0x7c 0x89 0xc5
0x00007c10 <bogus+ 16>: 0xb9 0x10 0x00 0xb8 0x01 0x13 0xbb 0x0c
0x00007c18 <bogus+ 24>: 0x00 0xb2 0x00 0xcd 0x10 0xc3 0x48 0x65
0x00007c20 <bogus+ 32>: 0x6c 0x6c 0x6f 0x2c 0x20 0x4f 0x53 0x20
0x00007c28 <bogus+ 40>: 0x77 0x6f 0x72 0x6c 0x64 0x21 0x00 0x00
0x00007c30 <bogus+ 48>: 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
0x00007c38 <bogus+ 56>: 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00

<bochs:5> n
Next at t=12943101
(0) [0x0000000000007c02] 0000:7c02 (unk. ctxt): mov ds, ax ; 8ed8


<bochs:6> trace-reg on
Register-Tracing enabled for CPU0
<bochs:7> n
Next at t=12943102
eax: 0x00000000 0
ecx: 0x00090000 589824
edx: 0x00000000 0
ebx: 0x00000000 0
esp: 0x0000ffd6 65494
ebp: 0x00000000 0
esi: 0x000e34e0 931040
edi: 0x0000ffac 65452
eip: 0x00007c04
eflags 0x00000082: id vip vif ac vm rf nt IOPL=0 of df if tf SF zf af pf cf
(0) [0x0000000000007c04] 0000:7c04 (unk. ctxt): mov es, ax ; 8ec0

<bochs:8> c

此时出现Hello, OS world! 的红色字样!
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值