从patch整体来看, 2.6.24后lguest是较早切入了Kernel的启动过程,而2.6.23是后期才切入。
一 2.6.23之前
在
中说到How does the kernel know it’s an lguest
guest? The
first code the x86 kernel runs are is startup_32 in
head.S. This tests if paging is already enabled: if it is,
we know
we’re under some kind of hypervisor. We end up trying all the registered
paravirt_probe func-
tions, and end up in the one in
drivers/lguest/lguest.c.
见
中lguest_maybe_init 函数
二
2.6.23
但是出现了变化
下面的链接
[PATCH 2/3] lguest: 2.6.21-mm1
update: lguest-magic-signature.patch
解释了在2.6.23.2内核代码,
启动过程:
函数调用流程
main函数的流程(Documentation/lguest/lguest.c)
1 . 得到第一条指令地址,返回在start中(实际为entry_point(
Documentation/lguest/lguest.c)
start
= load_kernel(open_or_die(argv[optind+1], O_RDONLY), &page_offset);
2
初始化各寄存器, 为启动做好准备
tell_kernel(pgdir, start, page_offset)
=> write=> initialize(file, (const u32 __user *)input); ==>
setup_regs(lg->regs, args[2]); 将准备好cs:eip
3 run_guest
entry_point(
Documentation/lguest/lguest.c)==>GenuineLguest(drivers/lguest/lguest_asm.S)
==> lguest_init (drivers/lguest/lguest.c)=>start_kernel
三
2.6.24
次要变化: 对page_offset的处理
[RFC
PATCH 2/3] lguest: Boot with virtual == physical to get closer to
native Linux.
正
式的补丁
[patch 31/43]
lguest: Boot with virtual == physical to get closer to native Linux.
主要
变化:修改了Boot protocol , 增加虚拟机启动标志
见
Documentation/i386/boot.txt(自2.6.24开始)
[Lguest] [PATCH 0/5]
Boot protocol changes
[PATCH
4/5] Revert lguest magic and use hook in head.S
2.6.34
的具体分析
从map_elf 和load_bzimage来看, lguest的启动直接跳过setup()函数, 而进入
/arch/x86/kernel/head_32.S
中的startup_32(), 参见ULK 3RD 附录A.
startup_32有对lguest的入口
lguest_entry,在arch/x86/lguest/i386_head.S中有ENTRY(lguest_entry)
#ifdef
CONFIG_PARAVIRT
/* This is can only trip for a broken
bootloader... */
cmpw $0x207, pa(boot_params + BP_version)
jb default_entry
/* Paravirt-compatible boot parameters. Look to
see what architecture
we're booting under. */
movl
pa(boot_params + BP_hardware_subarch), %eax
cmpl
$num_subarch_entries, %eax
jae bad_subarch
movl
pa(subarch_entries)(,%eax,4), %eax
subl $__PAGE_OFFSET, %eax
jmp *%eax
在main()(
Documentation/lguest/lguest.c)函数中有如下代码, 可见根本不需要修改内核映像vmlinux或bzImage,
而是直接在代码中设定
/* Boot protocol version: 2.07 supports the
fields for lguest. */
boot->hdr.version = 0x207;
/*
The hardware_subarch value of "1" tells the Guest it's an lguest. */
boot->hdr.hardware_subarch = 1;
阅读(896) | 评论(0) | 转发(0) |