一个操作系统的实现笔记1:环境搭建

1、在虚拟机上装好linux,如ubuntu。

2、在ubuntu上安装bochs。

虚拟机安装linux就不说了,网上很多教程,说一下在ubuntu下安装bochs方法,先下载bochs源码:http://download.csdn.net/download/u014783685/9985590,然后将bochs-2.4.5.tar.gz复制到ubuntu,依次执行以下命令:

tar xvf bochs-2.4.5.tar.gz

cd bochs-2.4.5

./configure --enable-debugger --enable-disasm //为了支持调试功能,生成Makefile

make

make install

在执行./configure --enable-debugger --enable-disasm 可能会出现一些错误,可以在这里查看错误原因和处理方法:

http://blog.csdn.net/dc_726/article/details/48414271
http://blog.csdn.net/liu0808/article/details/53086578

在此感谢上面两位作者列出的错误和处理方法.

安装好bochs后,新建目录test,在下面新建bochsrc、bootsect.s、Makefile三个文件,三个文件内容如下:

*******************************************************bochsrc*****************************************************************

###############################################################
# Configuration file for Bochs
###############################################################

# how much memory the emulated machine will have
megs: 32


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

# what disk images will be used
floppya: 1_44=boot.img, status=inserted

# choose the boot disk.
boot: a
#boot: disk

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

# disable the mouse
mouse: enabled=0

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

#注意上面的/usr/local/share/bochs要修改为自己的bochs安装目录

*******************************************************Makefile*****************************************************************

TARGET : boot.img

AS = as
LD = ld
ASFLAG = --32
LDFLAG = -m elf_i386 --oformat binary -Ttext=0x7c00

%.o:%.s                           
$(AS) $(ASFLAG) -o $@ $<

boot.img:bootsect.bin
sudo dd bs=1024 count=1440 if=/dev/zero    of=boot.img
sudo dd bs=512  count=1    if=bootsect.bin of=boot.img conv=notrunc

bootsect.bin:bootsect.o
$(LD) $(LDFLAG) -o $@ $<

clean:
rm -f *.bin *.o *.img *.txt

*******************************************************bootsect.s*****************************************************************

.code16
.text
.globl _start
_start:
movw %cs,%ax #设置段寄存器
movw %ax,%ds
movw %ax,%es
call DispStr
1:
jmp 1b  

DispStr:
movw $Strsize,%bx
movw (%bx),%cx  
movw $BootMessage,%ax 
movw %ax,%bp   #es:bp 显示字符串地址
movw $0x1301,%ax   #ah=0x13在teletype模式下显示字符串 al=1 显示属性在bl
movw $0x000c,%bx   #显示颜色,背景色
movw $0x0a20,%dx   #dh:行 dl:列
int  $0x10
ret

BootMessage:
.asciz "Hello world!" #以0结尾的字符串

Strsize:
.word Strsize-BootMessage

.org 510
.word 0xaa55

然后在该目录下执行bochs,出现bochs启动画面后,在按回车即可看到红色的Hello world!。

猜你喜欢

转载自blog.csdn.net/u014783685/article/details/78030053