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)
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值