WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-ppc-devel

[XenPPC] [xenppc-unstable] [ppc] Dom0 can be either a 64bit or 32 bit im

To: xen-ppc-devel@xxxxxxxxxxxxxxxxxxx
Subject: [XenPPC] [xenppc-unstable] [ppc] Dom0 can be either a 64bit or 32 bit image
From: Xen patchbot-xenppc-unstable <patchbot-xenppc-unstable@xxxxxxxxxxxxxxxxxxx>
Date: Wed, 28 Jun 2006 19:40:41 +0000
Delivery-date: Wed, 28 Jun 2006 12:48:09 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-ppc-devel-request@lists.xensource.com?subject=help>
List-id: Xen PPC development <xen-ppc-devel.lists.xensource.com>
List-post: <mailto:xen-ppc-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-ppc-devel>, <mailto:xen-ppc-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-ppc-devel>, <mailto:xen-ppc-devel-request@lists.xensource.com?subject=unsubscribe>
Reply-to: xen-ppc-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-ppc-devel-bounces@xxxxxxxxxxxxxxxxxxx
# HG changeset patch
# User Jimi Xenidis <jimix@xxxxxxxxxxxxxx>
# Node ID 10db0f8c710da9d581a03d72594b063858833a97
# Parent  5c9944b054ed33acedf90ca77673e0990d434c67
[ppc] Dom0 can be either a 64bit or 32 bit image

This allows the use of a zImage which is smaller and also can package
a ramdisk with the kernel which may be necessesary in some installs.
One day a true boot loader will arrive, please Santa.. PLEASE!!

Signed-off-by: Jimi Xenidis <jimix@xxxxxxxxxxxxxx>
---
 xen/arch/ppc/Makefile        |    3 
 xen/arch/ppc/domain_build.c  |  150 ++++++++++++++++++++++---------------------
 xen/arch/ppc/elf32.c         |    5 +
 xen/arch/ppc/oftree.h        |    3 
 xen/include/asm-ppc/config.h |    2 
 5 files changed, 90 insertions(+), 73 deletions(-)

diff -r 5c9944b054ed -r 10db0f8c710d xen/arch/ppc/Makefile
--- a/xen/arch/ppc/Makefile     Wed Jun 28 15:29:04 2006 -0400
+++ b/xen/arch/ppc/Makefile     Wed Jun 28 15:37:45 2006 -0400
@@ -42,9 +42,10 @@ obj-$(builtin_dom0) += dom0.o
 
 obj-y += firmware_image.o
 
+obj-y += elf32.o
+
 CFLAGS += -Wundef -Wpointer-arith
 CFLAGS += -Wmissing-prototypes -Wmissing-declarations -Wpacked
-CFLAGS += -Wredundant-decls
 
 LINK=0x3000000
 boot32_link_base = $(LINK)
diff -r 5c9944b054ed -r 10db0f8c710d xen/arch/ppc/domain_build.c
--- a/xen/arch/ppc/domain_build.c       Wed Jun 28 15:29:04 2006 -0400
+++ b/xen/arch/ppc/domain_build.c       Wed Jun 28 15:37:45 2006 -0400
@@ -30,8 +30,10 @@
 #include <asm/papr.h>
 #include "oftree.h"
 
+extern int parseelfimage_32(struct domain_setup_info *dsi);
+extern int loadelfimage_32(struct domain_setup_info *dsi);
+
 /* opt_dom0_mem: memory allocated to domain 0. */
-
 static unsigned int opt_dom0_mem;
 static void parse_dom0_mem(char *s)
 {
@@ -46,23 +48,16 @@ custom_param("dom0_mem", parse_dom0_mem)
 
 int elf_sanity_check(Elf_Ehdr *ehdr)
 {
-#if !defined(ELFSIZE)
-#error "Must pick a default ELFSIZE"
-#endif
-
     if (IS_ELF(*ehdr))
-#if ELFSIZE == 32
-        if (ehdr->e_ident[EI_CLASS] == ELFCLASS32
-            && ehdr->e_machine == EM_PPC)
-#elif ELFSIZE == 64
-        if (ehdr->e_ident[EI_CLASS] == ELFCLASS64
-             && ehdr->e_machine == EM_PPC64)
-#else
-#error "unknown ELFSIZE"
-#endif
+        /* we are happy with either */
+        if ((ehdr->e_ident[EI_CLASS] == ELFCLASS32
+             && ehdr->e_machine == EM_PPC)
+            || (ehdr->e_ident[EI_CLASS] == ELFCLASS64
+                && ehdr->e_machine == EM_PPC64)) {
             if (ehdr->e_ident[EI_DATA] == ELFDATA2MSB
-                 && ehdr->e_type == ET_EXEC)
+                && ehdr->e_type == ET_EXEC)
                 return 1;
+        }
     printk("DOM0 image is not a Xen-compatible Elf image.\n");
     return 0;
 }
@@ -70,24 +65,20 @@ int elf_sanity_check(Elf_Ehdr *ehdr)
 /* adapted from common/elf.c */
 #define RM_MASK(a,l) ((a) & ((1UL << (l)) - 1))
 
-static inline int is_loadable_phdr(Elf_Phdr *phdr)
-{
-    return ((phdr->p_type == PT_LOAD) &&
-            ((phdr->p_flags & (PF_W|PF_X)) != 0));
-}
-
-static int rm_loadelfimage(struct domain_setup_info *dsi, ulong rma)
+static int rm_loadelfimage_64(struct domain_setup_info *dsi, ulong rma)
 {
     char *elfbase = (char *)dsi->image_addr;
-    Elf_Ehdr *ehdr = (Elf_Ehdr *)dsi->image_addr;
-    Elf_Phdr *phdr;
+    Elf64_Ehdr *ehdr = (Elf64_Ehdr *)dsi->image_addr;
+    Elf64_Phdr *phdr;
     int h;
   
     for (h = 0; h < ehdr->e_phnum; h++ ) 
     {
-        phdr = (Elf_Phdr *)(elfbase + ehdr->e_phoff + (h*ehdr->e_phentsize));
-        if (!is_loadable_phdr(phdr))
+        phdr = (Elf64_Phdr *)(elfbase + ehdr->e_phoff + (h*ehdr->e_phentsize));
+        if (!((phdr->p_type == PT_LOAD) &&
+             ((phdr->p_flags & (PF_W|PF_X)) != 0)))
             continue;
+
         if (phdr->p_filesz != 0)
             memcpy((char *)(rma + RM_MASK(phdr->p_paddr, 42)),
                    elfbase + phdr->p_offset, 
@@ -118,6 +109,10 @@ int construct_dom0(struct domain *d,
     ulong rma = d->arch.rma_base;
     start_info_t *si;
     ulong eomem;
+    int am64 = 1;
+    ulong msr;
+    ulong pc;
+    ulong r2;
 
     /* Sanity! */
     BUG_ON(d->domain_id != 0);
@@ -129,8 +124,11 @@ int construct_dom0(struct domain *d,
     dsi.image_addr = image_start;
     dsi.image_len  = image_len;
 
-    if ((rc = parseelfimage(&dsi)) != 0)
-        return rc;
+    if ((rc = parseelfimage(&dsi)) != 0) {
+        if ((rc = parseelfimage_32(&dsi)) != 0)
+            return rc;
+        am64 = 0;
+    }
 
     /* elf contains virtual addresses that can have the upper bits
      * masked while running in real mode, so we do the masking as well
@@ -186,10 +184,6 @@ int construct_dom0(struct domain *d,
     /* copy relative to Xen */
     dst += rma;
 
-
-    extern int firmware_image_start[0];
-    extern int firmware_image_size[0];
-
     ASSERT((dst - rma) + (ulong)firmware_image_size < eomem);
     printk("loading OFH: 0x%lx, RMA: 0x%lx\n", dst, dst - rma);
     memcpy((void *)dst, firmware_image_start, (ulong)firmware_image_size);
@@ -208,27 +202,58 @@ int construct_dom0(struct domain *d,
     memcpy((void *)dst, (void *)oftree, oftree_len);
 
     dst = ALIGN_UP(dst + oftree_len, PAGE_SIZE);
-    printk("loading Dom0: 0x%lx, in RMA:0x%lx\n", dst, dst - rma);
-    rm_loadelfimage(&dsi, dst);
-
-    ulong kbase = dst;
-
-    /* move dst to end of bss */
-    dst = ALIGN_UP(dsi.v_kernend + dst, PAGE_SIZE);
-    if ( initrd_len > 0 ) {
-        ASSERT( (dst - rma) + image_len < eomem );
-
-        printk("loading initrd: 0x%lx, 0x%lx\n", dst, initrd_len);
-        memcpy((void *)dst, (void *)initrd_start, initrd_len);
-
-        si->mod_start = dst - rma;
-        si->mod_len = image_len;
-
-        dst = ALIGN_UP(dst + initrd_len, PAGE_SIZE);
+
+    if (am64) {
+        ulong kbase;
+        ulong *fdesc;
+
+        printk("loading 64-bit Dom0: 0x%lx, in RMA:0x%lx\n", dst, dst - rma);
+        rm_loadelfimage_64(&dsi, dst);
+
+        kbase = dst;
+        /* move dst to end of bss */
+        dst = ALIGN_UP(dsi.v_kernend + dst, PAGE_SIZE);
+
+        if ( initrd_len > 0 ) {
+            ASSERT( (dst - rma) + image_len < eomem );
+
+            printk("loading initrd: 0x%lx, 0x%lx\n", dst, initrd_len);
+            memcpy((void *)dst, (void *)initrd_start, initrd_len);
+
+            si->mod_start = dst - rma;
+            si->mod_len = image_len;
+
+            dst = ALIGN_UP(dst + initrd_len, PAGE_SIZE);
+        } else {
+            printk("no initrd\n");
+            si->mod_start = 0;
+            si->mod_len = 0;
+        }
+        /* it may be a function descriptor */
+        fdesc = (ulong *)(dsi.v_kernstart + dsi.v_kernentry + kbase);
+
+        if (fdesc[2] == 0
+            && ((fdesc[0] >= dsi.v_kernstart)
+                && (fdesc[0] < dsi.v_kernend)) /* text entry is in range */
+            && ((fdesc[1] >= dsi.v_kernstart)  /* toc can be > image */
+                && (fdesc[1] < (dsi.v_kernend + (0x7fff * sizeof (ulong)))))) {
+            /* it is almost certainly a function descriptor */
+            pc = RM_MASK(fdesc[0], 42) + kbase - rma;
+            r2 = RM_MASK(fdesc[1], 42) + kbase - rma;
+        } else {
+            pc = ((ulong)fdesc) - rma;
+            r2 = 0;
+        }
+        msr = MSR_SF;
     } else {
-        printk("no initrd\n");
-        si->mod_start = 0;
-        si->mod_len = 0;
+        printk("loading 32-bit Dom0: 0x%lx, in RMA:0x%lx\n",
+               dsi.v_kernstart + rma, dsi.v_kernstart);
+        dsi.v_start = rma;
+        loadelfimage_32(&dsi);
+
+        pc = dsi.v_kernentry;
+        r2 = 0;
+        msr = 0;
     }
 
     v->arch.ctxt.gprs[3] = si->mod_start;
@@ -238,26 +263,7 @@ int construct_dom0(struct domain *d,
     if ( cmdline != NULL )
         strncpy((char *)si->cmd_line, cmdline, sizeof(si->cmd_line)-1);
 
-    /* set up the MSR how we like it */
-    v->arch.ctxt.msr = MSR_SF;
-
-    ulong *fdesc = (ulong *)(dsi.v_kernstart + dsi.v_kernentry + kbase);
-    ulong pc;
-    ulong r2;
-
-    if (fdesc[2] == 0  /* could be a true function descriptor */
-        && ((fdesc[0] >= dsi.v_kernstart)
-            && (fdesc[0] < dsi.v_kernend)) /* text entry is in range */
-        && ((fdesc[1] >= dsi.v_kernstart)  /* toc can be greater than image */
-            && (fdesc[1] < (dsi.v_kernend + (0x7fff * sizeof (ulong)))))) {
-        /* it is almost certainly a function descriptor */
-        pc = RM_MASK(fdesc[0], 42) + kbase - rma;
-        r2 = RM_MASK(fdesc[1], 42) + kbase - rma;
-    } else {
-        pc = ((ulong)fdesc) - rma;
-        r2 = 0;
-    }
-
+    v->arch.ctxt.msr = msr;
     v->arch.ctxt.pc = pc;
     v->arch.ctxt.gprs[2] = r2;
 
diff -r 5c9944b054ed -r 10db0f8c710d xen/arch/ppc/oftree.h
--- a/xen/arch/ppc/oftree.h     Wed Jun 28 15:29:04 2006 -0400
+++ b/xen/arch/ppc/oftree.h     Wed Jun 28 15:37:45 2006 -0400
@@ -27,4 +27,7 @@ extern int ofd_dom0_fixup(
 extern int ofd_dom0_fixup(
     struct domain *d, ulong oftree, start_info_t *si, ulong dst);
 
+extern int firmware_image_start[0];
+extern int firmware_image_size[0];
+
 #endif  /* #ifndef _OFTREE_H */
diff -r 5c9944b054ed -r 10db0f8c710d xen/include/asm-ppc/config.h
--- a/xen/include/asm-ppc/config.h      Wed Jun 28 15:29:04 2006 -0400
+++ b/xen/include/asm-ppc/config.h      Wed Jun 28 15:37:45 2006 -0400
@@ -52,7 +52,9 @@ extern char __bss_start[];
 #define CONFIG_PCI 1
 #define NR_CPUS 1
 
+#ifndef ELFSIZE
 #define ELFSIZE 64
+#endif
 
 #define asmlinkage
 
diff -r 5c9944b054ed -r 10db0f8c710d xen/arch/ppc/elf32.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/xen/arch/ppc/elf32.c      Wed Jun 28 15:37:45 2006 -0400
@@ -0,0 +1,5 @@
+#define parseelfimage parseelfimage_32
+#define loadelfimage loadelfimage_32
+#define ELFSIZE 32
+#include "../../common/elf.c"
+

_______________________________________________
Xen-ppc-devel mailing list
Xen-ppc-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-ppc-devel

<Prev in Thread] Current Thread [Next in Thread>
  • [XenPPC] [xenppc-unstable] [ppc] Dom0 can be either a 64bit or 32 bit image, Xen patchbot-xenppc-unstable <=