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)

你可能感兴趣的:(ios)