Re: [Xen-devel] PATCH 2/3: Support booting relocatable kernels

Daniel P. Berrange
Wed, 19 Dec 2007 05:42:41 -0000

This patch introduces the basic infrastructure for direct kernel
boot in the ioemu copy of QEMU. The current #ifdef disabled
code is actually obsolete wrt to upstream QEMU code. So this
is removed entirely. In its place I have imported the latest
upstream QEMU code. The QEMU code assumes that the guest RAM
is directly mapped into the QEMU process, so there were some
changes neccessary. Instead of strcpy/memcpy''ing the args
and kernel header into guest RAM, cpu_physical_memory_rw is
used. Intead of fread() the initrd and kernel into guest RAM
a helper function is used fread2guest which reads into a small
buffer and then uses cpu_physical_memory_rw.

NB in reading the following, Documentation/i386/boot.txt is
a useful reference for what''s going on.

Next, instead of loading the kernel at 0x100000, this code
loads it at 0x200000. This is far enough away that there''s
no risk of it overlapping with the HVM firmware image. If the
Linux kernel boot protocol is 0x205 or later, and the flag
at offset 0x234 in the kernel header is 1, then the guest
kernel was built with CONFIG_RELOCATABLE=y.

In this scenario we merely need to tell the kernel what address
it has been relocated to by writing 0x200000 into the kernel
header at offset 0x214. When switching from real mode into
protected mode the kernel will immediately start executing at
0x200000 and be happy with life. This should work for 2.6.20 or
later on i386, and 2.6.22 or later on x86_64.

This has been verified with Fedora 7 and Fedora 8 bare metal kernels
on i386 from the $TREE/images/pxeboot of the install trees.

NB x86_64 is not yet tested

 pc.c |  352 ++++++++++++++++++++++++++++++++++++++++++++++++++-----------------
 1 file changed, 265 insertions(+), 87 deletions(-)


  Signed-off-by: Daniel P. Berrange <berrange@redhat.com>