ia64/xen-unstable

changeset 5577:0b5f09002630

bitkeeper revision 1.1752 (42bbe5ba5hLPfcw1f77_F22fq6v6Yw)

The set of patches below add support for loading plan9's a.out
format using the linux builder. This is considerably simpler
than having a seperate builder, shares more code and should
be easier to maintain. Hopefully the original plan9 builder
can go away in the future.

I've been able to test this manually with vm-tools but am
still having some problems (unrelated I think) with xm.

Signed-off-by: Tim Newsham <newsham@lava.net>
author kaf24@firebug.cl.cam.ac.uk
date Fri Jun 24 10:51:38 2005 +0000 (2005-06-24)
parents 48dd03e4b388
children b38b3893fa76
files .rootkeys tools/libxc/Makefile tools/libxc/xc_aout9.h tools/libxc/xc_linux_build.c tools/libxc/xc_load_aout9.c tools/libxc/xc_private.h
line diff
     1.1 --- a/.rootkeys	Fri Jun 24 10:46:24 2005 +0000
     1.2 +++ b/.rootkeys	Fri Jun 24 10:51:38 2005 +0000
     1.3 @@ -736,6 +736,7 @@ 41dde8afKYRKxS4XtLv1KUegGQy_bg tools/lib
     1.4  41cc934abX-QLXJXW_clV_wRjM0zYg tools/libxc/plan9a.out.h
     1.5  3fbba6dc1uU7U3IFeF6A-XEOYF2MkQ tools/libxc/rpm.spec
     1.6  3fbba6dcrNxtygEcgJYAJJ1gCQqfsA tools/libxc/xc.h
     1.7 +42bbe5b9J1BFuxACiiyj38Fucc2xgg tools/libxc/xc_aout9.h
     1.8  3fbba6dbEVkVMX0JuDFzap9jeaucGA tools/libxc/xc_bvtsched.c
     1.9  4273458dyF2_sKA6CFkNJQYb8eY2dA tools/libxc/xc_core.c
    1.10  3fbba6dbasJQV-MVElDC0DGSHMiL5w tools/libxc/xc_domain.c
    1.11 @@ -745,6 +746,7 @@ 4227c129ZKjJPNYooHVzBCyinf7Y6Q tools/lib
    1.12  3fbba6dbNCU7U6nsMYiXzKkp3ztaJg tools/libxc/xc_linux_build.c
    1.13  3fbba6dbl267zZOAVHYLOdLCdhcZMw tools/libxc/xc_linux_restore.c
    1.14  3fbba6db7li3FJiABYtCmuGxOJxEGw tools/libxc/xc_linux_save.c
    1.15 +42bbe5b95gdEdSyDdrK2ts7GEiK5Mw tools/libxc/xc_load_aout9.c
    1.16  42a40bc3vE3p9fPSJZQZK0MdQF9B8g tools/libxc/xc_load_bin.c
    1.17  42a40bc4diWfFsPGf0RW7qXMufU4YQ tools/libxc/xc_load_elf.c
    1.18  3fbba6db7WnnJr0KFrIFrqNlSKvFYg tools/libxc/xc_misc.c
     2.1 --- a/tools/libxc/Makefile	Fri Jun 24 10:46:24 2005 +0000
     2.2 +++ b/tools/libxc/Makefile	Fri Jun 24 10:51:38 2005 +0000
     2.3 @@ -19,6 +19,7 @@ SRCS     += xc_core.c
     2.4  SRCS     += xc_domain.c
     2.5  SRCS     += xc_evtchn.c
     2.6  SRCS     += xc_gnttab.c
     2.7 +SRCS     += xc_load_aout9.c
     2.8  SRCS     += xc_load_bin.c
     2.9  SRCS     += xc_load_elf.c
    2.10  SRCS     += xc_linux_build.c
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/tools/libxc/xc_aout9.h	Fri Jun 24 10:51:38 2005 +0000
     3.3 @@ -0,0 +1,30 @@
     3.4 +
     3.5 +typedef struct	Exec
     3.6 +{
     3.7 +	long	magic;		/* magic number */
     3.8 +	long	text;	 	/* size of text segment */
     3.9 +	long	data;	 	/* size of initialized data */
    3.10 +	long	bss;	  	/* size of uninitialized data */
    3.11 +	long	syms;	 	/* size of symbol table */
    3.12 +	long	entry;	 	/* entry point */
    3.13 +	long	spsz;		/* size of pc/sp offset table */
    3.14 +	long	pcsz;		/* size of pc/line number table */
    3.15 +} Exec;
    3.16 +
    3.17 +#define	_MAGIC(b)	((((4*b)+0)*b)+7)
    3.18 +#define	A_MAGIC		_MAGIC(8)	/* 68020 */
    3.19 +#define	I_MAGIC		_MAGIC(11)	/* intel 386 */
    3.20 +#define	J_MAGIC		_MAGIC(12)	/* intel 960 (retired) */
    3.21 +#define	K_MAGIC		_MAGIC(13)	/* sparc */
    3.22 +#define	V_MAGIC		_MAGIC(16)	/* mips 3000 BE */
    3.23 +#define	X_MAGIC		_MAGIC(17)	/* att dsp 3210 (retired) */
    3.24 +#define	M_MAGIC		_MAGIC(18)	/* mips 4000 BE */
    3.25 +#define	D_MAGIC		_MAGIC(19)	/* amd 29000 (retired) */
    3.26 +#define	E_MAGIC		_MAGIC(20)	/* arm */
    3.27 +#define	Q_MAGIC		_MAGIC(21)	/* powerpc */
    3.28 +#define	N_MAGIC		_MAGIC(22)	/* mips 4000 LE */
    3.29 +#define	L_MAGIC		_MAGIC(23)	/* dec alpha */
    3.30 +#define	P_MAGIC		_MAGIC(24)	/* mips 3000 LE */
    3.31 +#define	U_MAGIC		_MAGIC(25)	/* sparc64 */
    3.32 +#define	S_MAGIC		_MAGIC(26)	/* amd64 */
    3.33 +
     4.1 --- a/tools/libxc/xc_linux_build.c	Fri Jun 24 10:46:24 2005 +0000
     4.2 +++ b/tools/libxc/xc_linux_build.c	Fri Jun 24 10:51:38 2005 +0000
     4.3 @@ -14,6 +14,7 @@
     4.4  
     4.5  
     4.6  #include "xc_elf.h"
     4.7 +#include "xc_aout9.h"
     4.8  #include <stdlib.h>
     4.9  #include <zlib.h>
    4.10  
    4.11 @@ -38,7 +39,8 @@ static int probeimageformat(char *image,
    4.12                              struct load_funcs *load_funcs)
    4.13  {
    4.14      if ( probe_elf(image, image_size, load_funcs) &&
    4.15 -         probe_bin(image, image_size, load_funcs) )
    4.16 +         probe_bin(image, image_size, load_funcs) &&
    4.17 +	 probe_aout9(image, image_size, load_funcs) )
    4.18      {
    4.19          ERROR( "Unrecognized image format" );
    4.20          return -EINVAL;
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/tools/libxc/xc_load_aout9.c	Fri Jun 24 10:51:38 2005 +0000
     5.3 @@ -0,0 +1,166 @@
     5.4 +
     5.5 +#include "xc_private.h"
     5.6 +#include "xc_aout9.h"
     5.7 +
     5.8 +#if defined(__i386__)
     5.9 +  #define A9_MAGIC I_MAGIC
    5.10 +#elif defined(__x86_64__)
    5.11 +  #define A9_MAGIC S_MAGIC
    5.12 +#elif defined(__ia64__)
    5.13 +  #define A9_MAGIC 0
    5.14 +#else
    5.15 +#error "Unsupported architecture"
    5.16 +#endif
    5.17 +
    5.18 +
    5.19 +#define round_pgup(_p)    (((_p)+(PAGE_SIZE-1))&PAGE_MASK)
    5.20 +#define round_pgdown(_p)  ((_p)&PAGE_MASK)
    5.21 +
    5.22 +static int parseaout9image(char *, unsigned long, struct domain_setup_info *);
    5.23 +static int loadaout9image(char *, unsigned long, int, u32, unsigned long *, struct domain_setup_info *);
    5.24 +static void copyout(int, u32, unsigned long *, unsigned long, void *, int);
    5.25 +struct Exec *get_header(unsigned char *, unsigned long, struct Exec *);
    5.26 +
    5.27 +
    5.28 +int 
    5.29 +probe_aout9(
    5.30 +    char *image,
    5.31 +    unsigned long image_size,
    5.32 +    struct load_funcs *load_funcs)
    5.33 +{
    5.34 +    struct Exec ehdr;
    5.35 +
    5.36 +    if (!get_header(image, image_size, &ehdr)) {
    5.37 +        ERROR("Kernel image does not have a a.out9 header.");
    5.38 +        return -EINVAL;
    5.39 +    }
    5.40 +
    5.41 +    load_funcs->parseimage = parseaout9image;
    5.42 +    load_funcs->loadimage = loadaout9image;
    5.43 +    return 0;
    5.44 +}
    5.45 +
    5.46 +static int 
    5.47 +parseaout9image(
    5.48 +    char *image,
    5.49 +    unsigned long image_size,
    5.50 +    struct domain_setup_info *dsi)
    5.51 +{
    5.52 +    struct Exec ehdr;
    5.53 +    unsigned long start, txtsz, end;
    5.54 +
    5.55 +    if (!get_header(image, image_size, &ehdr)) {
    5.56 +        ERROR("Kernel image does not have a a.out9 header.");
    5.57 +        return -EINVAL;
    5.58 +    }
    5.59 +
    5.60 +    if (sizeof ehdr + ehdr.text + ehdr.data > image_size) {
    5.61 +        ERROR("a.out program extends past end of image.");
    5.62 +        return -EINVAL;
    5.63 +    }
    5.64 +
    5.65 +    start = round_pgdown(ehdr.entry);
    5.66 +    txtsz = round_pgup(ehdr.text);
    5.67 +    end = start + txtsz + ehdr.data + ehdr.bss;
    5.68 +
    5.69 +    dsi->v_start	= start;
    5.70 +    dsi->v_kernstart	= start;
    5.71 +    dsi->v_kernend	= end;
    5.72 +    dsi->v_kernentry	= ehdr.entry;
    5.73 +    dsi->v_end		= end;
    5.74 +
    5.75 +    /* XXX load symbols */
    5.76 +
    5.77 +    return 0;
    5.78 +}
    5.79 +
    5.80 +static int 
    5.81 +loadaout9image(
    5.82 +    char *image,
    5.83 +    unsigned long image_size,
    5.84 +    int xch, u32 dom,
    5.85 +    unsigned long *parray,
    5.86 +    struct domain_setup_info *dsi)
    5.87 +{
    5.88 +    struct Exec ehdr;
    5.89 +    unsigned long txtsz;
    5.90 +
    5.91 +    if (!get_header(image, image_size, &ehdr)) {
    5.92 +        ERROR("Kernel image does not have a a.out9 header.");
    5.93 +        return -EINVAL;
    5.94 +    }
    5.95 +
    5.96 +    txtsz = round_pgup(ehdr.text);
    5.97 +    copyout(xch, dom, parray, 
    5.98 +            0, image, sizeof ehdr + ehdr.text);
    5.99 +    copyout(xch, dom, parray, 
   5.100 +            txtsz, image + sizeof ehdr + ehdr.text, ehdr.data);
   5.101 +    /* XXX zeroing of BSS needed? */
   5.102 +
   5.103 +    /* XXX load symbols */
   5.104 +
   5.105 +    return 0;
   5.106 +}
   5.107 +
   5.108 +/*
   5.109 + * copyout data to the domain given an offset to the start
   5.110 + * of its memory region described by parray.
   5.111 + */
   5.112 +static void
   5.113 +copyout(
   5.114 +    int xch, u32 dom,
   5.115 +    unsigned long *parray,
   5.116 +    unsigned long off,
   5.117 +    void *buf,
   5.118 +    int sz)
   5.119 +{
   5.120 +    unsigned long pgoff, chunksz;
   5.121 +    void *pg;
   5.122 +
   5.123 +    while (sz > 0) {
   5.124 +        pgoff = off & (PAGE_SIZE-1);
   5.125 +        chunksz = sz;
   5.126 +        if(chunksz > PAGE_SIZE - pgoff)
   5.127 +            chunksz = PAGE_SIZE - pgoff;
   5.128 +
   5.129 +        pg = xc_map_foreign_range(xch, dom, PAGE_SIZE, PROT_WRITE, 
   5.130 +                                  parray[off>>PAGE_SHIFT]);
   5.131 +        memcpy(pg + pgoff, buf, chunksz);
   5.132 +        munmap(pg, PAGE_SIZE);
   5.133 +
   5.134 +        off += chunksz;
   5.135 +        buf += chunksz;
   5.136 +        sz -= chunksz;
   5.137 +    }
   5.138 +}
   5.139 +    
   5.140 +/*
   5.141 + * Decode the header from the start of image and return it.
   5.142 + */
   5.143 +struct Exec *
   5.144 +get_header(
   5.145 +    unsigned char *image,
   5.146 +    unsigned long image_size,
   5.147 +    struct Exec *ehdr)
   5.148 +{
   5.149 +    unsigned long *v;
   5.150 +    int i;
   5.151 +
   5.152 +    if (A9_MAGIC == 0)
   5.153 +        return 0;
   5.154 +
   5.155 +    if (image_size < sizeof ehdr)
   5.156 +        return 0;
   5.157 +
   5.158 +    /* ... all big endian words */
   5.159 +    v = (unsigned long *)ehdr;
   5.160 +    for (i = 0; i < sizeof *ehdr; i += 4) {
   5.161 +        v[i/4] = (image[i+0]<<24) | (image[i+1]<<16) | 
   5.162 +                 (image[i+2]<<8) | image[i+3];
   5.163 +    }
   5.164 +
   5.165 +    if(ehdr->magic != A9_MAGIC)
   5.166 +        return 0;
   5.167 +    return ehdr;
   5.168 +}
   5.169 +
     6.1 --- a/tools/libxc/xc_private.h	Fri Jun 24 10:46:24 2005 +0000
     6.2 +++ b/tools/libxc/xc_private.h	Fri Jun 24 10:51:38 2005 +0000
     6.3 @@ -310,5 +310,6 @@ int pin_table(int xc_handle, unsigned in
     6.4  /* image loading */
     6.5  int probe_elf(char *image, unsigned long image_size, struct load_funcs *funcs);
     6.6  int probe_bin(char *image, unsigned long image_size, struct load_funcs *funcs);
     6.7 +int probe_aout9(char *image, unsigned long image_size, struct load_funcs *funcs);
     6.8  
     6.9  #endif /* __XC_PRIVATE_H__ */