Skip to contentSkip to conversation

domain builder for ReactOS

PATCH In review Ge van Geldorp 4 participants 10 messages Jun 2, 2005 – Jun 6, 2005 Arm/actions semi architecture

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 domain builder for ReactOS

As announced earlier (http://lists.xensource.com/archives/html/xen-devel/2005-03/msg01160.html)
I'm working on porting ReactOS to Xen. The first stage, getting our bootloader running, is complete now. Progress report and a screenshot on
http://reactos.com/wiki/index.php/Xen_port

To start ReactOS in a Xen domain, a ReactOS domain builder is needed. Patches to implement that are included below. I'm not sure about the Signed-Off-By stuff, is just including the line below enough or is some paperwork required?

Ge van Geldorp.

tools/libxc/xc.h +9 -0
@@ -273,6 +273,15 @@
                  unsigned int control_evtchn,
                  unsigned long flags);
 
+int xc_reactos_build(int xc_handle,
+                     u32 domid,
+                     const char *image_name,
+                     const char *module_name,
+                     const char *cmdline,
+                     unsigned int control_evtchn,
+                     unsigned long flags,
+                     unsigned int vcpus);
+
 int xc_bvtsched_global_set(int xc_handle,
                            unsigned long ctx_allow);
 
tools/python/xen/lowlevel/xc/xc.c +38 -0
@@ -391,6 +391,33 @@
     return zero;
 }
 
+static PyObject *pyxc_reactos_build(PyObject *self,
+                                    PyObject *args,
+                                    PyObject *kwds)
+{
+    XcObject *xc = (XcObject *)self;
+
+    u32   dom;
+    char *image, *module = NULL, *cmdline = "";
+    int   control_evtchn, flags = 0, vcpus = 1;
+
+    static char *kwd_list[] = { "dom", "control_evtchn", 
+                                "image", "ramdisk", "cmdline", "flags", "vcpus",
+                                NULL };
+
+    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "iis|ssii", kwd_list, 
+                                      &dom, &control_evtchn, 
+                                      &image, &module, &cmdline, &flags, &vcpus) )
+        return NULL;
+
+    if ( xc_reactos_build(xc->xc_handle, dom, image,
+                          module, cmdline, control_evtchn, flags, vcpus) != 0 )
+        return PyErr_SetFromErrno(xc_error);
+    
+    Py_INCREF(zero);
+    return zero;
+}
+
 static PyObject *pyxc_bvtsched_global_set(PyObject *self,
                                           PyObject *args,
                                           PyObject *kwds)
@@ -942,6 +969,17 @@
       " cmdline [str, n/a]: Kernel parameters, if any.\n\n"
       "Returns: [int] 0 on success; -1 on error.\n" },
 
+    { "reactos_build", 
+      (PyCFunction)pyxc_reactos_build, 
+      METH_VARARGS | METH_KEYWORDS, "\n"
+      "Build a new ReactOS guest OS.\n"
+      " dom     [int]:      Identifier of domain to build into.\n"
+      " image   [str]:      Name of kernel image file. May be gzipped.\n"
+      " ramdisk [str, n/a]: Name of ramdisk file, if any.\n"
+      " cmdline [str, n/a]: Kernel parameters, if any.\n\n"
+      " vcpus   [int, 1]:   Number of Virtual CPUS in domain.\n\n"
+      "Returns: [int] 0 on success; -1 on error.\n" },
+
     { "bvtsched_global_set",
       (PyCFunction)pyxc_bvtsched_global_set,
       METH_VARARGS | METH_KEYWORDS, "\n"
tools/python/xen/xend/XendDomainInfo.py +22 -3
@@ -1167,6 +1167,24 @@
     vm.create_domain("vmx", kernel, ramdisk, cmdline, memmap)
     return vm
 
+def vm_image_reactos(vm, image):
+    """Create a VM for a ReactOS image.
+
+    @param name:      vm name
+    @param memory:    vm memory
+    @param image:     image config
+    @return: vm
+    """
+    kernel = sxp.child_value(image, "kernel")
+    cmdline = ""
+    args = sxp.child_value(image, "args")
+    if args:
+        cmdline += " " + args
+    ramdisk = sxp.child_value(image, "ramdisk", '')
+    log.debug("creating reactos domain with cmdline: %s" %(cmdline,))
+    vm.create_domain("reactos", kernel, ramdisk, cmdline)
+    return vm
+
 def vm_field_ignore(vm, config, val, index):
     """Dummy config field handler used for fields with built-in handling.
 
@@ -1196,9 +1214,10 @@
 
 #============================================================================
 # Register image handlers.
-add_image_handler('linux', vm_image_linux)
-add_image_handler('plan9', vm_image_plan9)
-add_image_handler('vmx',   vm_image_vmx)
+add_image_handler('linux',   vm_image_linux)
+add_image_handler('plan9',   vm_image_plan9)
+add_image_handler('vmx',     vm_image_vmx)
+add_image_handler('reactos', vm_image_reactos)
 
 # Ignore the fields we already handle.
 add_config_handler('name',       vm_field_ignore)
tools/libxc/Makefile +1 -0
@@ -28,6 +28,7 @@
 SRCS     += xc_private.c
 SRCS     += xc_ptrace.c
 SRCS     += xc_ptrace_core.c
+SRCS     += xc_reactos_build.c
 SRCS     += xc_vmx_build.c
 
 CFLAGS   += -Wall
tools/libxc/xc_reactos_build.c new file +652 -0

652 lines not on this page · raw message

#1 lore raw
Quoted 7 lines · Ge van Geldorp

As announced earlier (http://lists.xensource.com/archives/html/xen-devel/2005-03/msg01160.html)
I'm working on porting ReactOS to Xen. The first stage, getting our bootloader running, is complete now. Progress report and a screenshot on
http://reactos.com/wiki/index.php/Xen_port

To start ReactOS in a Xen domain, a ReactOS domain builder is needed. Patches to implement that are included below.

I'm not too keen on this approach: we try to keep the number of domain builders small. Ideally we'd only want one builder for paravirtualized guests and one for hardware assisted guests. For paravirtualized guests, this is the mis-named "linux builder". We have a plan9 specific builder because plan9 uses a.out, but I think it would be preferable to support additional file format loaders within the linux builder.

Why do you think that you need a different builder? Especially since you're going to use a bootloader anyway, your actual kernel image file can be of whatever format you like... If your main/only struggle is with the ELF format, then please consider adding support for additional loaders in the existing builder.

christian

#2 lore raw
Quoted 8 lines

From: Christian Limpach

Why do you think that you need a different builder? Especially since you're going to use a bootloader anyway, your actual kernel image file can be of whatever format you like... If your main/only struggle is with the ELF format, then please consider adding support for additional loaders in the existing builder.

Yes, the reason for the different builder is that our bootloader is not in ELF format. I'm not sure the linux ELF loader and my loader are going to have much code in common, which is why I opted for a different builder. However, I don't see major problems adding the code to the Linux builder, so if that's what you prefer, that's how I'll do it.

Gé van Geldorp.

#3 lore raw
Quoted 11 lines · Ge van Geldorp
Quoted 8 lines

From: Christian Limpach

Why do you think that you need a different builder? Especially since you're going to use a bootloader anyway, your actual kernel image file can be of whatever format you like... If your main/only struggle is with the ELF format, then please consider adding support for additional loaders in the existing builder.

Yes, the reason for the different builder is that our bootloader is not in ELF format.

Well, your webpage says that right now you're building your loader as an ELF image and I guess use the linux builder? Can't you stick with that? Even if it's inconvenient to only being able to build the loader on Linux, how often does the loader need to be rebuilt?

Quoted 2 lines

I'm not sure the linux ELF loader and my loader are going to have much code in common, which is why I opted for a different builder.

The elf loading functions in xc_linux_build make up less than half of the file -- ideally you should be able to use the setup_guest and xc_linux_build functions without too many changes.

I'd suggest that you move the elf loading functions into a separate file (xc_load_elf.c) and put your load functions in a different file.

You'll also need to add a probe function to identify the type of the image, which could then return a pointer to a struct with function pointers to parseelfimage/loadelfimage in the elf case and then call these through the pointers.

Quoted 2 lines

However, I don't see major problems adding the code to the Linux builder, so if that's what you prefer, that's how I'll do it.

The other question is whether it makes much sense to add a loader/builder before there's a kernel?

christian

#4 lore raw
Quoted 4 lines

From: Christian Limpach

Well, your webpage says that right now you're building your loader as an ELF image and I guess use the linux builder?

Correct.

Quoted 3 lines

Can't you stick with that?
Even if it's inconvenient to only being able to build the loader on Linux, how often does the loader need to be rebuilt?

No, building as an ELF image is only possible as long as I'm using a branch for development. Most of our developers are building on Windows, not on Linux, so the question "how often" becomes kind of moot. They would simply be unable to build the bootloader, ever. We see the bootloader as an integrated part of our project, so that would not be acceptable.

Perhaps a little more background on the bootloader and why we need it: it is normally built as a binary (unstructured) image, which is loaded by the partition bootsector. It is also multiboot-compliant, so another way to load it is using Grub. The bootloader will load the kernel and the infamous registry. The registry contains (amongst a lot of other stuff) a list of boot-time drivers. The bootloader will parse the registry and load the required drivers. It will then do some hardware detection and transfer control to the kernel. The tricky part is that it's the bootloader which determines which drivers to load.
I estimate that about 80% of our users (testers really) are not using Grub but are using the bootsector method of getting the loader into memory. This implies the binary format, there simply isn't enough space in the bootsector to parse ELF headers. So we're stuck with the binary format.

Quoted 2 lines

The other question is whether it makes much sense to add a loader/builder before there's a kernel?

The reason I'm submitting a Xen patch at this point is that I've completed a well-defined task now (getting the bootloader to run under Xen) and it's a good point to merge the development branch into the main trunk. However, I do need to get rid of the ELF format to do that. And that in turn means I can no longer use the current linux builder/loader in Xen.

Ge van Geldorp.

#5 lore raw
Quoted 5 lines · Ge van Geldorp

The reason I'm submitting a Xen patch at this point is that I've completed a well-defined task now (getting the bootloader to run under Xen) and it's a good point to merge the development branch into the main trunk. However, I do need to get rid of the ELF format to do that. And that in turn means I can no longer use the current linux builder/loader in Xen.

Xen domUs need to have a bios, so we do not need to have domain-specific stuff like ELF-parsing in dom0. I will post to source to my 'mstrap' attempt at this tomorrow for people to comment on.

Jacob

#6 lore raw
Quoted 3 lines · Jacob Gorm Hansen

Xen domUs need to have a bios, so we do not need to have domain-specific stuff like ELF-parsing in dom0. I will post to source to my 'mstrap' attempt at this tomorrow for people to comment on.

This is an option, but definitely not appropriate for every environment.

christian

#7 lore raw
Quoted 8 lines · Christian Limpach
Quoted 3 lines · Jacob Gorm Hansen

Xen domUs need to have a bios, so we do not need to have domain-specific stuff like ELF-parsing in dom0. I will post to source to my 'mstrap' attempt at this tomorrow for people to comment on.

This is an option, but definitely not appropriate for every environment.

Seems to work well for VMWare. Could you give an example of an environment where this would not be appropriate?

Jacob

#8 lore raw
Quoted 8 lines · Jacob Gorm Hansen
Quoted 7 lines · Christian Limpach
Quoted 3 lines · Jacob Gorm Hansen

Xen domUs need to have a bios, so we do not need to have domain-specific stuff like ELF-parsing in dom0. I will post to source to my 'mstrap' attempt at this tomorrow for people to comment on.

Quoted 4 lines
Quoted 1 line

This is an option, but definitely not appropriate for every environment.

Seems to work well for VMWare. Could you give an example of an environment where this would not be appropriate?

The model you suggest requires you to install the kernel such that it is accessible from within the guest environment. This is not always desirable nor practical.
[some off-list exchange skipped]
I like the loader + "ramdisk" solution. Can you reuse the code we have in the builder now to load elf, elf w/ symtab and bin images? Isn't the development environment for the loader too hostile? I implemented a similar loader for NetBSD when the linux dom0 loader didn't support elf yet -- it was quite tedious to relocate stuff in memory so that the layout would be the same for the loader and the image it would execute...

christian

#9 lore raw
Quoted 13 lines · Christian Limpach

On 6/6/05, Jacob Gorm Hansen <[email protected]> wrote:

The model you suggest requires you to install the kernel such that it is accessible from within the guest environment. This is not always desirable nor practical.
[some off-list exchange skipped]
I like the loader + "ramdisk" solution. Can you reuse the code we have in the builder now to load elf, elf w/ symtab and bin images? Isn't the development environment for the loader too hostile? I implemented a similar loader for NetBSD when the linux dom0 loader didn't support elf yet -- it was quite tedious to relocate stuff in memory so that the layout would be the same for the loader and the image it would execute...

My code is a port of the loader as per last autumn (I forward-ported my old code to the new Xen), so right now it only loads ELF, I guess I could work in later changes as well.

You are right that developing stage2 loaders is harder than writing Linux binaries, though with a serial cable things are not too bad. The worst part is turning over control to the OS itself, because you need a temporary overlap of address spaces, and you would like to free some of the original domain memory, or at least hand it over the OS.

Jacob