`

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

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

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

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

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

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! 的红色字样!
分享到:
评论

相关推荐

    Bochs入门教程[操作系统第一步]

    在80x86 IBM PC 兼容计算机上用一张软盘启动引导程序,最后打印出下面的字样: Hello world! The current time is hh:mm:ss.(动态输出时间) ...5、是写操作系统的第一步!! 6、可执行源码和详细教程。

    自己动手写操作系统

    第1章 马上动手写一个最小的"操作系统"1 1.1 准备工作1 1.2 10分钟完成的操作系统1 1.3 Boot Sector3 1.4 代码解释3 1.5 水面下的冰山5 1.6 回顾6 第2章 搭建你的工作环境7 2.1 虚拟计算机(Virtual PC)7 ...

    自己动手写操作系统 电子工业出版社 pdf

    第1章 马上动手写一个最小的“操作系统”1 1.1 准备工作1 1.2 10分钟完成的操作系统1 1.3 Boot Sector3 1.4 代码解释3 1.5 水面下的冰山5 1.6 回顾6 第2章 搭建你的工作环境7 2.1 虚拟计算机(Virtual PC)7 2.1.1 ...

    自己动手写操作系统 pdf

    第1章 马上动手写一个最小的“操作系统”1 1.1 准备工作1 1.2 10分钟完成的操作系统1 1.3 Boot Sector3 1.4 代码解释3 1.5 水面下的冰山5 1.6 回顾6 第2章 搭建你的工作环境7 2.1 虚拟计算机(Virtual PC)7 2.1.1 ...

    boot-sector:这是用于操作系统启动的引导扇区汇编代码!

    这是书中的源代码:“如何制作一个简单的...Eg: nasm boot_helloworld.asm -f bin -o boot_helloworld.bin 中银国际使用: QEMU 用法: qemu-system-i386 [bin_filename] Eg: qemu-system-i386 boot_helloworld.bin

    黑客反汇编揭秘(第二版).part1.rar

    第1章 携黑客工具启程 2 1.1 调试器 2 1.2 反汇编器 6 1.3 反编译器 8 1.4 十六进制编辑器 10 1.5 解包器(Unpacker) 12 1.6 转储器 13 1.7 资源编辑器 14 1.8 窥测器(Spy) 14 1.9 监视器(Monitor) 15...

    黑客反汇编揭秘(第二版).part2.rar

    第1章 携黑客工具启程 2 1.1 调试器 2 1.2 反汇编器 6 1.3 反编译器 8 1.4 十六进制编辑器 10 1.5 解包器(Unpacker) 12 1.6 转储器 13 1.7 资源编辑器 14 1.8 窥测器(Spy) 14 1.9 监视器(Monitor) 15...

    x86 x64体系探索及编程part1

    目录 第一篇 x86 基础 第1 章数与数据类型2 1.1 数 2 1.1.1 数字 2 1.1.2 二进制数 3 1.1.3 二进制数的排列 3 1.1.4 十六进制数 5 1.1.5 八进制数与十进制数 5 1.2 数据类型 6 1.2.1 integer 数 6 1.2.2 floating-...

    x86 x64体系探索及编程part3

    目录 第一篇 x86 基础 第1 章数与数据类型2 1.1 数 2 1.1.1 数字 2 1.1.2 二进制数 3 1.1.3 二进制数的排列 3 1.1.4 十六进制数 5 1.1.5 八进制数与十进制数 5 1.2 数据类型 6 1.2.1 integer 数 6 1.2.2 floating-...

    x86 x64体系探索及编程part4

    目录 第一篇 x86 基础 第1 章数与数据类型2 1.1 数 2 1.1.1 数字 2 1.1.2 二进制数 3 1.1.3 二进制数的排列 3 1.1.4 十六进制数 5 1.1.5 八进制数与十进制数 5 1.2 数据类型 6 1.2.1 integer 数 6 1.2.2 floating-...

    x86 x64体系探索及编程 part2

    目录 第一篇 x86 基础 第1 章数与数据类型2 1.1 数 2 1.1.1 数字 2 1.1.2 二进制数 3 1.1.3 二进制数的排列 3 1.1.4 十六进制数 5 1.1.5 八进制数与十进制数 5 1.2 数据类型 6 1.2.1 integer 数 6 1.2.2 floating-...

Global site tag (gtag.js) - Google Analytics