Xen上的miniOS

原文:
http://qyrekcah.spaces.live.com/blog/cns!D691A70904EDECB0!228.entry?wa=wsignin1.0&sa=674975121
在Xen上可以运行的最小OS,该miniOS直接用汇编程序编写,实现了Xen的hypercall的调用。下面是它的实现代码:

# helloworld.s
.section __xen_guest
.ascii "GUEST_OS=MyOS"
.ascii ",XEN_VER=xen-3.0"
.ascii ",HYPERCALL_PAGE=0x2"
.ascii ",LOADER=generic"
.ascii ",PT_MODE_WRITABLE"
.byte 0
.text# text section为可执行的程序代码(executable program code)
.globl _start# Guest OS的入口为_start
_start:
cld#cld(Clear Decimal Flag) 设置ALU为二进制模式
#设置hypercall 参数
movl $18, %eax # __Hypervisor_console_io
movl $0, %ebx # CONSOLEIO_write
movl $hello_message_len, %ecx # buffer length
movl $hello_message, %edx # buffer virtual address
int $0x82#使用int $0x82执行hypercall
#调用关机和关闭电源hypercall
movl $6, %eax # __Hypervisor_sched_op_compat
movl $2, %ebx # SCHEDOP_shutdown
movl $0, %ecx # SHUTDOWN_poweroff
int $0x82
hang:
jmp hang # shouldn't get here
.data# 数据段(data section)
hello_message: .ascii "This is the hello world program./n"
hello_message_len = . -hello_message#hello消息的长度,.表示当前offset
编译时使用的Makefile为
helloworld: helloworld.s
as -o helloworld.o -a=helloworld.l helloworld.s
ld -Ttext 0x100000 -o helloworld.elf helloworld.o
该虚拟机的配置文件为
kernel = "helloworld.elf"
memory = 32
name = "HelloWorld"
on_crash = 'destroy'#当domain crash时指定guest的行动(behaviour)
07-04
minios目前已经完成的功能:<br>bootsector<br>进入保护模式<br>内存分配模块<br>简单的线程调度模块<br>信号量<br>时钟<br>统一的设备驱动模型<br>标准输入输出设备驱动<br>内存及字符串相关的标准C库函数<br><br><br>附件codes.zip的目录结构如下:<br>codes<br>|-relocate 连接程序的源代码,将bootsector和minios连接成一个可启动的磁盘镜像<br>|-bootsector bootsector的源代码<br>|-minios minios的源代码<br>|-bin 所有的目标都在此目录中。其中minios.vhd就是可启动的磁盘镜像<br><br>如何启动minios:<br>你必须安装Microsoft的Virtual PC 2007<br>你可以在微软的官方网站下载他的安装程序,程序大小约30M<br>http://download.microsoft.com/download/8/5/6/856bfc39-fa48-4315-a2b3-e6697a54ca88/32%20BIT/setup.exe<br>安装完成后就可以双击codes/bin/vm.vmc运行minios了<br><br>如何编译minios:<br>编译minios共需要三种编译器。<br>codes/bootsector/bootsector.asm必须用nasm进行编译,将编译的结果命名为bootsector并且拷贝到codes/bin<br>codes/minios/platform/platform.asm必须用masm32进行编译,编译的结果在codes/minios/platform/platform.obj<br>其余的代码都用vc6编译即可,vc6的工程在codes/minios/minios.dsw<br>如果你手边没有nasm和masm32,不要紧,因为这两个文件一般不需要改动,直接用我编译好的目标文件就可以了<br><br>双击minios.dsw打开vc6,点击菜单Project->Project Setting->Debug,修改Executable for debug session一栏<br>将Virtual PC.exe的完整路径填入。如果你安装在默认的路径下,就不需要修改它。<br>然后直接Ctrl-F5运行就可以编译并且运行了。<br>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值