ia64/xen-unstable

changeset 15689:d83c9d87ede4

merge with xen-unstable.hg
author Alex Williamson <alex.williamson@hp.com>
date Wed Aug 01 16:40:30 2007 -0600 (2007-08-01)
parents 77c87416fbd0 88bb0d305308
children 0cf0feba58fb
files xen/arch/ia64/xen/dom_fw_dom0.c
line diff
     1.1 --- a/tools/blktap/drivers/blktapctrl.c	Wed Aug 01 09:40:58 2007 -0600
     1.2 +++ b/tools/blktap/drivers/blktapctrl.c	Wed Aug 01 16:40:30 2007 -0600
     1.3 @@ -42,6 +42,7 @@
     1.4  #include <errno.h>
     1.5  #include <sys/types.h>
     1.6  #include <linux/types.h>
     1.7 +#include <sys/wait.h>
     1.8  #include <signal.h>
     1.9  #include <fcntl.h>
    1.10  #include <sys/poll.h>
    1.11 @@ -472,11 +473,38 @@ static int read_msg(int fd, int msgtype,
    1.12  
    1.13  }
    1.14  
    1.15 +int launch_tapdisk(char *wrctldev, char *rdctldev)
    1.16 +{
    1.17 +	char *argv[] = { "tapdisk", wrctldev, rdctldev, NULL };
    1.18 +	pid_t child;
    1.19 +	
    1.20 +	if ((child = fork()) < 0)
    1.21 +		return -1;
    1.22 +
    1.23 +	if (!child) {
    1.24 +		int i;
    1.25 +		for (i = 0 ; i < sysconf(_SC_OPEN_MAX) ; i++)
    1.26 +			if (i != STDIN_FILENO &&
    1.27 +			    i != STDOUT_FILENO &&
    1.28 +			    i != STDERR_FILENO)
    1.29 +				close(i);
    1.30 +
    1.31 +		execvp("tapdisk", argv);
    1.32 +		_exit(1);
    1.33 +	} else {
    1.34 +		pid_t got;
    1.35 +		do {
    1.36 +			got = waitpid(child, NULL, 0);
    1.37 +		} while (got != child);
    1.38 +	}
    1.39 +	return 0;
    1.40 +}
    1.41 +
    1.42  int blktapctrl_new_blkif(blkif_t *blkif)
    1.43  {
    1.44  	blkif_info_t *blk;
    1.45  	int major, minor, fd_read, fd_write, type, new;
    1.46 -	char *rdctldev, *wrctldev, *cmd, *ptr;
    1.47 +	char *rdctldev, *wrctldev, *ptr;
    1.48  	image_t *image;
    1.49  	blkif_t *exist = NULL;
    1.50  	static uint16_t next_cookie = 0;
    1.51 @@ -504,12 +532,6 @@ int blktapctrl_new_blkif(blkif_t *blkif)
    1.52  				free(rdctldev);
    1.53  				return -1;
    1.54  			}
    1.55 -			if (asprintf(&cmd, "tapdisk %s %s", wrctldev, rdctldev) == -1) {
    1.56 -				free(rdctldev);
    1.57 -				free(wrctldev);
    1.58 -				return -1;
    1.59 -			}
    1.60 -
    1.61  			blkif->fds[READ] = open_ctrl_socket(rdctldev);
    1.62  			blkif->fds[WRITE] = open_ctrl_socket(wrctldev);
    1.63  			
    1.64 @@ -517,15 +539,14 @@ int blktapctrl_new_blkif(blkif_t *blkif)
    1.65  				goto fail;
    1.66  
    1.67  			/*launch the new process*/
    1.68 -			DPRINTF("Launching process, CMDLINE [%s]\n",cmd);
    1.69 -			if (system(cmd) == -1) {
    1.70 -				DPRINTF("Unable to fork, cmdline: [%s]\n",cmd);
    1.71 + 			DPRINTF("Launching process, CMDLINE [tapdisk %s %s]\n",wrctldev, rdctldev);
    1.72 + 			if (launch_tapdisk(wrctldev, rdctldev) == -1) {
    1.73 + 				DPRINTF("Unable to fork, cmdline: [tapdisk %s %s]\n",wrctldev, rdctldev);
    1.74  				return -1;
    1.75  			}
    1.76  
    1.77  			free(rdctldev);
    1.78  			free(wrctldev);
    1.79 -			free(cmd);
    1.80  		} else {
    1.81  			DPRINTF("Process exists!\n");
    1.82  			blkif->fds[READ] = exist->fds[READ];
    1.83 @@ -605,7 +626,6 @@ int open_ctrl_socket(char *devname)
    1.84  {
    1.85  	int ret;
    1.86  	int ipc_fd;
    1.87 -	char *cmd;
    1.88  	fd_set socks;
    1.89  	struct timeval timeout;
    1.90  
     2.1 --- a/tools/blktap/lib/blktaplib.h	Wed Aug 01 09:40:58 2007 -0600
     2.2 +++ b/tools/blktap/lib/blktaplib.h	Wed Aug 01 16:40:30 2007 -0600
     2.3 @@ -169,12 +169,14 @@ typedef struct image {
     2.4  	unsigned int info;
     2.5  } image_t;
     2.6  
     2.7 +/* 16-byte message header, immediately followed by message payload. */
     2.8  typedef struct msg_hdr {
     2.9 -	uint16_t    type;
    2.10 +	uint16_t   type;
    2.11  	uint16_t   len;
    2.12  	uint16_t   drivertype;
    2.13  	uint16_t   cookie;
    2.14  	uint8_t    readonly;
    2.15 +	uint8_t    pad[7];
    2.16  } msg_hdr_t;
    2.17  
    2.18  typedef struct msg_newdev {
     3.1 --- a/tools/firmware/hvmloader/smbios.c	Wed Aug 01 09:40:58 2007 -0600
     3.2 +++ b/tools/firmware/hvmloader/smbios.c	Wed Aug 01 16:40:30 2007 -0600
     3.3 @@ -169,7 +169,7 @@ hvm_write_smbios_tables(void)
     3.4      /* temporary variables used to build up Xen version string */
     3.5      char *p = NULL; /* points to next point of insertion */
     3.6      unsigned len = 0; /* length of string already composed */
     3.7 -    char *tmp = NULL; /* holds result of itoa() */
     3.8 +    char tmp[16]; /* holds result of itoa() */
     3.9      unsigned tmp_len; /* length of next string to add */
    3.10  
    3.11      hypercall_xen_version(XENVER_guest_handle, uuid);
     4.1 --- a/tools/libxc/ia64/Makefile	Wed Aug 01 09:40:58 2007 -0600
     4.2 +++ b/tools/libxc/ia64/Makefile	Wed Aug 01 16:40:30 2007 -0600
     4.3 @@ -5,6 +5,8 @@ GUEST_SRCS-y += ia64/xc_ia64_linux_save.
     4.4  GUEST_SRCS-y += ia64/xc_ia64_linux_restore.c
     4.5  
     4.6  GUEST_SRCS-y += ia64/xc_dom_ia64_util.c
     4.7 +GUEST_SRCS-y += ia64/dom_fw_acpi.c
     4.8 +
     4.9  DOMFW_SRCS_BASE := dom_fw_common.c dom_fw_domu.c dom_fw_asm.S
    4.10  DOMFW_SRCS := $(addprefix ia64/, $(DOMFW_SRCS_BASE))
    4.11  $(DOMFW_SRCS):
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/tools/libxc/ia64/dom_fw_acpi.c	Wed Aug 01 16:40:30 2007 -0600
     5.3 @@ -0,0 +1,13 @@
     5.4 +#include <inttypes.h>
     5.5 +#include <xen/acpi.h>
     5.6 +
     5.7 +uint8_t
     5.8 +generate_acpi_checksum(void *tbl, unsigned long len)
     5.9 +{
    5.10 +    uint8_t *ptr, sum = 0;
    5.11 +
    5.12 +    for ( ptr = tbl; len > 0 ; len--, ptr++ )
    5.13 +        sum += *ptr;
    5.14 +
    5.15 +    return 0 - sum;
    5.16 +}
     6.1 --- a/tools/python/xen/util/acmpolicy.py	Wed Aug 01 09:40:58 2007 -0600
     6.2 +++ b/tools/python/xen/util/acmpolicy.py	Wed Aug 01 16:40:30 2007 -0600
     6.3 @@ -818,12 +818,13 @@ class ACMPolicy(XSPolicy):
     6.4              if successful,the policy's flags will indicate that the
     6.5              policy is the one loaded into the hypervisor
     6.6          """
     6.7 -        (ret, output) = commands.getstatusoutput(
     6.8 +        if not self.isloaded():
     6.9 +            (ret, output) = commands.getstatusoutput(
    6.10                                     security.xensec_tool +
    6.11                                     " loadpolicy " +
    6.12                                     self.get_filename(".bin"))
    6.13 -        if ret != 0:
    6.14 -            return -xsconstants.XSERR_POLICY_LOAD_FAILED
    6.15 +            if ret != 0:
    6.16 +                return -xsconstants.XSERR_POLICY_LOAD_FAILED
    6.17          return xsconstants.XSERR_SUCCESS
    6.18  
    6.19      def isloaded(self):
     7.1 --- a/tools/xenstore/utils.c	Wed Aug 01 09:40:58 2007 -0600
     7.2 +++ b/tools/xenstore/utils.c	Wed Aug 01 16:40:30 2007 -0600
     7.3 @@ -8,20 +8,19 @@
     7.4  #include <fcntl.h>
     7.5  #include <sys/types.h>
     7.6  #include <signal.h>
     7.7 -
     7.8  #include "utils.h"
     7.9  
    7.10  void xprintf(const char *fmt, ...)
    7.11  {
    7.12 -	static FILE *out = NULL;
    7.13  	va_list args;
    7.14 -	if (!out)
    7.15 -		out = stderr;
    7.16 +
    7.17 +	if (!stderr)
    7.18 +		return; /* could trace()? */
    7.19  
    7.20  	va_start(args, fmt);
    7.21 -	vfprintf(out, fmt, args);
    7.22 +	vfprintf(stderr, fmt, args);
    7.23  	va_end(args);
    7.24 -	fflush(out);
    7.25 +	fflush(stderr);
    7.26  }
    7.27  
    7.28  void barf(const char *fmt, ...)
    7.29 @@ -61,72 +60,3 @@ void barf_perror(const char *fmt, ...)
    7.30  	}
    7.31  	exit(1);
    7.32  }
    7.33 -
    7.34 -void *_realloc_array(void *ptr, size_t size, size_t num)
    7.35 -{
    7.36 -	if (num >= SIZE_MAX/size)
    7.37 -		return NULL;
    7.38 -	return realloc_nofail(ptr, size * num);
    7.39 -}
    7.40 -
    7.41 -void *realloc_nofail(void *ptr, size_t size)
    7.42 -{
    7.43 -	ptr = realloc(ptr, size);
    7.44 -	if (ptr)
    7.45 -		return ptr;
    7.46 -	barf("realloc of %zu failed", size);
    7.47 -}
    7.48 -
    7.49 -void *malloc_nofail(size_t size)
    7.50 -{
    7.51 -	void *ptr = malloc(size);
    7.52 -	if (ptr)
    7.53 -		return ptr;
    7.54 -	barf("malloc of %zu failed", size);
    7.55 -}
    7.56 -
    7.57 -/* This version adds one byte (for nul term) */
    7.58 -void *grab_file(const char *filename, unsigned long *size)
    7.59 -{
    7.60 -	unsigned int max = 16384;
    7.61 -	int ret, fd;
    7.62 -	void *buffer;
    7.63 -
    7.64 -	if (streq(filename, "-"))
    7.65 -		fd = dup(STDIN_FILENO);
    7.66 -	else
    7.67 -		fd = open(filename, O_RDONLY, 0);
    7.68 -
    7.69 -	if (fd == -1)
    7.70 -		return NULL;
    7.71 -
    7.72 -	buffer = malloc(max+1);
    7.73 -	if (!buffer)
    7.74 -		goto error;
    7.75 -	*size = 0;
    7.76 -	while ((ret = read(fd, buffer + *size, max - *size)) > 0) {
    7.77 -		*size += ret;
    7.78 -		if (*size == max) {
    7.79 -			void *nbuffer;
    7.80 -			max *= 2;
    7.81 -			nbuffer = realloc(buffer, max + 1);
    7.82 -			if (!nbuffer)
    7.83 -				goto error;
    7.84 -			buffer = nbuffer;
    7.85 -		}
    7.86 -	}
    7.87 -	if (ret < 0)
    7.88 -		goto error;
    7.89 -	((char *)buffer)[*size] = '\0';
    7.90 -	close(fd);
    7.91 -	return buffer;
    7.92 -error:
    7.93 -	free(buffer);
    7.94 -	close(fd);
    7.95 -	return NULL;
    7.96 -}
    7.97 -
    7.98 -void release_file(void *data, unsigned long size __attribute__((unused)))
    7.99 -{
   7.100 -	free(data);
   7.101 -}
     8.1 --- a/tools/xenstore/utils.h	Wed Aug 01 09:40:58 2007 -0600
     8.2 +++ b/tools/xenstore/utils.h	Wed Aug 01 16:40:30 2007 -0600
     8.3 @@ -21,39 +21,12 @@ static inline bool strends(const char *a
     8.4  
     8.5  #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
     8.6  
     8.7 -#define ___stringify(x)	#x
     8.8 -#define __stringify(x)		___stringify(x)
     8.9 -
    8.10 -/* Convenient wrappers for malloc and realloc.  Use them. */
    8.11 -#define new(type) ((type *)malloc_nofail(sizeof(type)))
    8.12 -#define new_array(type, num) realloc_array((type *)0, (num))
    8.13 -#define realloc_array(ptr, num) ((__typeof__(ptr))_realloc_array((ptr), sizeof((*ptr)), (num)))
    8.14 -
    8.15 -void *malloc_nofail(size_t size);
    8.16 -void *realloc_nofail(void *ptr, size_t size);
    8.17 -void *_realloc_array(void *ptr, size_t size, size_t num);
    8.18 -
    8.19  void barf(const char *fmt, ...) __attribute__((noreturn));
    8.20  void barf_perror(const char *fmt, ...) __attribute__((noreturn));
    8.21  
    8.22 -/* This version adds one byte (for nul term) */
    8.23 -void *grab_file(const char *filename, unsigned long *size);
    8.24 -void release_file(void *data, unsigned long size);
    8.25 -
    8.26 -/* Signal handling: returns fd to listen on. */
    8.27 -int signal_to_fd(int signal);
    8.28 -void close_signal(int fd);
    8.29 -
    8.30  void xprintf(const char *fmt, ...);
    8.31  
    8.32  #define eprintf(_fmt, _args...) xprintf("[ERR] %s" _fmt, __FUNCTION__, ##_args)
    8.33 -#define iprintf(_fmt, _args...) xprintf("[INF] %s" _fmt, __FUNCTION__, ##_args)
    8.34 -
    8.35 -#ifdef DEBUG
    8.36 -#define dprintf(_fmt, _args...) xprintf("[DBG] %s" _fmt, __FUNCTION__, ##_args)
    8.37 -#else
    8.38 -#define dprintf(_fmt, _args...) ((void)0)
    8.39 -#endif
    8.40  
    8.41  /*
    8.42   * Mux errno values onto returned pointers.
     9.1 --- a/tools/xenstore/xenstored_core.c	Wed Aug 01 09:40:58 2007 -0600
     9.2 +++ b/tools/xenstore/xenstored_core.c	Wed Aug 01 16:40:30 2007 -0600
     9.3 @@ -1820,7 +1820,9 @@ int main(int argc, char *argv[])
     9.4  	if (pidfile)
     9.5  		write_pidfile(pidfile);
     9.6  
     9.7 -	talloc_enable_leak_report_full();
     9.8 +	/* Talloc leak reports go to stderr, which is closed if we fork. */
     9.9 +	if (!dofork)
    9.10 +		talloc_enable_leak_report_full();
    9.11  
    9.12  	/* Create sockets for them to listen to. */
    9.13  	sock = talloc(talloc_autofree_context(), int);
    9.14 @@ -1881,6 +1883,11 @@ int main(int argc, char *argv[])
    9.15  		close(STDIN_FILENO);
    9.16  		close(STDOUT_FILENO);
    9.17  		close(STDERR_FILENO);
    9.18 +
    9.19 +		/* Get ourselves a nice xenstored crash if these are used. */
    9.20 +		stdin = NULL;
    9.21 +		stdout = NULL;
    9.22 +		stderr = NULL;
    9.23  	}
    9.24  
    9.25  	signal(SIGHUP, trigger_reopen_log);
    10.1 --- a/tools/xenstore/xenstored_domain.c	Wed Aug 01 09:40:58 2007 -0600
    10.2 +++ b/tools/xenstore/xenstored_domain.c	Wed Aug 01 16:40:30 2007 -0600
    10.3 @@ -621,13 +621,8 @@ void domain_entry_fix(unsigned int domid
    10.4  	struct domain *d;
    10.5  
    10.6  	d = find_domain_by_domid(domid);
    10.7 -	if (d) {
    10.8 -		if ((d->nbentry += num) < 0) {
    10.9 -			eprintf("invalid domain entry number %d",
   10.10 -				d->nbentry);
   10.11 -			d->nbentry = 0;
   10.12 -		}
   10.13 -	}
   10.14 +	if (d && ((d->nbentry += num) < 0))
   10.15 +		d->nbentry = 0;
   10.16  }
   10.17  
   10.18  int domain_entry(struct connection *conn)
    11.1 --- a/tools/xenstore/xs_tdb_dump.c	Wed Aug 01 09:40:58 2007 -0600
    11.2 +++ b/tools/xenstore/xs_tdb_dump.c	Wed Aug 01 16:40:30 2007 -0600
    11.3 @@ -4,7 +4,7 @@
    11.4  #include <fcntl.h>
    11.5  #include <stdio.h>
    11.6  #include <stdarg.h>
    11.7 -
    11.8 +#include <string.h>
    11.9  #include "xs_lib.h"
   11.10  #include "tdb.h"
   11.11  #include "talloc.h"
    12.1 --- a/tools/xm-test/lib/XmTestLib/acm.py	Wed Aug 01 09:40:58 2007 -0600
    12.2 +++ b/tools/xm-test/lib/XmTestLib/acm.py	Wed Aug 01 16:40:30 2007 -0600
    12.3 @@ -67,6 +67,10 @@ def ACMLoadPolicy(policy='xm-test'):
    12.4      if main.serverType == main.SERVER_XEN_API:
    12.5          ACMLoadPolicy_XenAPI()
    12.6      else:
    12.7 +        cmd='xm dumppolicy | grep -E "^POLICY REFERENCE = ' + policy + '.$"'
    12.8 +        s, o = traceCommand(cmd)
    12.9 +        if o != "":
   12.10 +            return
   12.11          s, o = traceCommand("xm makepolicy %s" % (policy))
   12.12          if s != 0:
   12.13              FAIL("Need to be able to do 'xm makepolicy %s' but could not" %
    13.1 --- a/tools/xm-test/tests/security-acm/07_security-acm_pol_update.py	Wed Aug 01 09:40:58 2007 -0600
    13.2 +++ b/tools/xm-test/tests/security-acm/07_security-acm_pol_update.py	Wed Aug 01 16:40:30 2007 -0600
    13.3 @@ -12,11 +12,20 @@ from xen.xend import XendAPIConstants
    13.4  from xen.util import acmpolicy, security, xsconstants
    13.5  from xen.util.acmpolicy import ACMPolicy
    13.6  from xen.xend.XendDomain import DOM0_UUID
    13.7 +from XmTestLib.acm import *
    13.8  
    13.9  import commands
   13.10  import os
   13.11  import base64
   13.12  
   13.13 +if not isACMEnabled():
   13.14 +    SKIP("Not running this test since ACM not enabled.")
   13.15 +
   13.16 +try:
   13.17 +    session = xapi.connect()
   13.18 +except:
   13.19 +    SKIP("Skipping this test since xm is not using the Xen-API.")
   13.20 +
   13.21  xm_test = {}
   13.22  xm_test['policyname'] = "xm-test"
   13.23  xm_test['date'] = "Fri Sep 29 14:44:38 2006"
    14.1 --- a/tools/xm-test/tests/security-acm/09_security-acm_pol_update.py	Wed Aug 01 09:40:58 2007 -0600
    14.2 +++ b/tools/xm-test/tests/security-acm/09_security-acm_pol_update.py	Wed Aug 01 16:40:30 2007 -0600
    14.3 @@ -7,6 +7,7 @@
    14.4  
    14.5  from XmTestLib import xapi
    14.6  from XmTestLib.XenAPIDomain import XmTestAPIDomain
    14.7 +from XmTestLib.acm import *
    14.8  from XmTestLib import *
    14.9  from xen.xend import XendAPIConstants
   14.10  from xen.util import security, xsconstants
   14.11 @@ -16,6 +17,14 @@ import base64
   14.12  import struct
   14.13  import time
   14.14  
   14.15 +if not isACMEnabled():
   14.16 +    SKIP("Not running this test since ACM not enabled.")
   14.17 +
   14.18 +try:
   14.19 +    session = xapi.connect()
   14.20 +except:
   14.21 +    SKIP("Skipping this test since xm is not using the Xen-API.")
   14.22 +
   14.23  def typestoxml(types):
   14.24      res = ""
   14.25      for t in types:
    15.1 --- a/xen/arch/ia64/xen/dom_fw_common.c	Wed Aug 01 09:40:58 2007 -0600
    15.2 +++ b/xen/arch/ia64/xen/dom_fw_common.c	Wed Aug 01 16:40:30 2007 -0600
    15.3 @@ -207,17 +207,6 @@ print_md(efi_memory_desc_t *md)
    15.4  		printk("(%luKB)\n", size >> 10);
    15.5  }
    15.6  
    15.7 -uint8_t
    15.8 -generate_acpi_checksum(void *tbl, unsigned long len)
    15.9 -{
   15.10 -	uint8_t *ptr, sum = 0;
   15.11 -
   15.12 -	for (ptr = tbl; len > 0 ; len--, ptr++)
   15.13 -		sum += *ptr;
   15.14 -
   15.15 -	return 0 - sum;
   15.16 -}
   15.17 -
   15.18  struct fake_acpi_tables {
   15.19  	struct acpi20_table_rsdp rsdp;
   15.20  	struct xsdt_descriptor_rev2 xsdt;
    16.1 --- a/xen/arch/ia64/xen/dom_fw_dom0.c	Wed Aug 01 09:40:58 2007 -0600
    16.2 +++ b/xen/arch/ia64/xen/dom_fw_dom0.c	Wed Aug 01 16:40:30 2007 -0600
    16.3 @@ -103,6 +103,7 @@ acpi_update_madt_checksum(unsigned long 
    16.4  /* base is physical address of acpi table */
    16.5  static void __init touch_acpi_table(void)
    16.6  {
    16.7 +	int result;
    16.8  	lsapic_nbr = 0;
    16.9  
   16.10  	if (acpi_table_parse_madt(ACPI_MADT_LSAPIC, acpi_update_lsapic, 0) < 0)
   16.11 @@ -111,6 +112,18 @@ static void __init touch_acpi_table(void
   16.12  				  acpi_patch_plat_int_src, 0) < 0)
   16.13  		printk("Error parsing MADT - no PLAT_INT_SRC entries\n");
   16.14  
   16.15 +	result = acpi_table_disable(ACPI_SRAT);
   16.16 +	if ( result == 0 )
   16.17 +		printk("Success Disabling SRAT\n");
   16.18 +	else if ( result != -ENOENT )
   16.19 +		printk("ERROR: Failed Disabling SRAT\n");
   16.20 +
   16.21 +	result = acpi_table_disable(ACPI_SLIT);
   16.22 +	if ( result == 0 )
   16.23 +		printk("Success Disabling SLIT\n");
   16.24 +	else if ( result != -ENOENT )
   16.25 +		printk("ERROR: Failed Disabling SLIT\n");
   16.26 +
   16.27  	acpi_table_parse(ACPI_APIC, acpi_update_madt_checksum);
   16.28  
   16.29  	return;
    17.1 --- a/xen/arch/powerpc/Makefile	Wed Aug 01 09:40:58 2007 -0600
    17.2 +++ b/xen/arch/powerpc/Makefile	Wed Aug 01 16:40:30 2007 -0600
    17.3 @@ -27,6 +27,7 @@ obj-y += memory.o
    17.4  obj-y += mm.o
    17.5  obj-y += mpic.o
    17.6  obj-y += mpic_init.o
    17.7 +obj-y += multiboot2.o
    17.8  obj-y += numa.o
    17.9  obj-y += of-devtree.o
   17.10  obj-y += of-devwalk.o
    18.1 --- a/xen/arch/powerpc/boot_of.c	Wed Aug 01 09:40:58 2007 -0600
    18.2 +++ b/xen/arch/powerpc/boot_of.c	Wed Aug 01 16:40:30 2007 -0600
    18.3 @@ -22,7 +22,6 @@
    18.4  #include <xen/config.h>
    18.5  #include <xen/init.h>
    18.6  #include <xen/lib.h>
    18.7 -#include <xen/multiboot.h>
    18.8  #include <xen/version.h>
    18.9  #include <xen/spinlock.h>
   18.10  #include <xen/serial.h>
   18.11 @@ -30,6 +29,7 @@
   18.12  #include <xen/sched.h>
   18.13  #include <asm/page.h>
   18.14  #include <asm/io.h>
   18.15 +#include <asm/boot.h>
   18.16  #include "exceptions.h"
   18.17  #include "of-devtree.h"
   18.18  #include "oftree.h"
   18.19 @@ -54,7 +54,6 @@ static ulong eomem;
   18.20  #define MEM_AVAILABLE_PAGES ((32 << 20) >> PAGE_SHIFT)
   18.21  static DECLARE_BITMAP(mem_available_pages, MEM_AVAILABLE_PAGES);
   18.22  
   18.23 -extern char builtin_cmdline[];
   18.24  extern struct ns16550_defaults ns16550;
   18.25  
   18.26  #undef OF_DEBUG
   18.27 @@ -648,23 +647,6 @@ static ulong boot_of_mem_init(void)
   18.28      return 0;
   18.29  }
   18.30  
   18.31 -static void boot_of_bootargs(multiboot_info_t *mbi)
   18.32 -{
   18.33 -    int rc;
   18.34 -
   18.35 -    if (builtin_cmdline[0] == '\0') {
   18.36 -        rc = of_getprop(bof_chosen, "bootargs", builtin_cmdline,
   18.37 -                CONFIG_CMDLINE_SIZE);
   18.38 -        if (rc > CONFIG_CMDLINE_SIZE)
   18.39 -            of_panic("bootargs[] not big enough for /chosen/bootargs\n");
   18.40 -    }
   18.41 -
   18.42 -    mbi->flags |= MBI_CMDLINE;
   18.43 -    mbi->cmdline = (ulong)builtin_cmdline;
   18.44 -
   18.45 -    of_printf("bootargs = %s\n", builtin_cmdline);
   18.46 -}
   18.47 -
   18.48  static int save_props(void *m, ofdn_t n, int pkg)
   18.49  {
   18.50      int ret;
   18.51 @@ -933,8 +915,8 @@ static void __init boot_of_fix_maple(voi
   18.52          }
   18.53      }
   18.54  }
   18.55 -    
   18.56 -static int __init boot_of_serial(void *oft)
   18.57 +
   18.58 +void __init boot_of_serial(void *oft)
   18.59  {
   18.60      int n;
   18.61      int p;
   18.62 @@ -1014,11 +996,9 @@ static int __init boot_of_serial(void *o
   18.63                    __func__, ns16550.irq);
   18.64          ns16550.irq = 0;
   18.65      }
   18.66 -
   18.67 -    return 1;
   18.68  }
   18.69  
   18.70 -static int __init boot_of_rtas(module_t *mod, multiboot_info_t *mbi)
   18.71 +static int __init boot_of_rtas(void)
   18.72  {
   18.73      int rtas_node;
   18.74      int rtas_instance;
   18.75 @@ -1065,14 +1045,13 @@ static int __init boot_of_rtas(module_t 
   18.76      rtas_end = mem + size;
   18.77      rtas_msr = of_msr;
   18.78  
   18.79 -    mod->mod_start = rtas_base;
   18.80 -    mod->mod_end = rtas_end;
   18.81      return 1;
   18.82  }
   18.83  
   18.84 -static void * __init boot_of_devtree(module_t *mod, multiboot_info_t *mbi)
   18.85 +void __init *boot_of_devtree(void)
   18.86  {
   18.87      void *oft;
   18.88 +    ulong oft_sz = 48 * PAGE_SIZE;
   18.89      ulong alloc_sz = 32 << 10;    /* 32KiB should be plenty */
   18.90      ulong sz;
   18.91  
   18.92 @@ -1100,108 +1079,9 @@ static void * __init boot_of_devtree(mod
   18.93  
   18.94      ofd_walk(oft, __func__, OFD_ROOT, /* add_hype_props */ NULL, 2);
   18.95  
   18.96 -    mod->mod_start = (ulong)oft;
   18.97 -    mod->mod_end = ALIGN_UP(mod->mod_start + sz, PAGE_SIZE);
   18.98 -
   18.99 -    if (mod->mod_end -mod->mod_start > alloc_sz)
  18.100 -        of_panic("Could not fit all devtree module in 0x%lx of memory\n",
  18.101 -            alloc_sz);
  18.102 -
  18.103 -    of_printf("%s: devtree mod @ 0x%016x - 0x%016x\n", __func__,
  18.104 -              mod->mod_start, mod->mod_end);
  18.105 -
  18.106 -    return oft;
  18.107 -}
  18.108 -
  18.109 -static void * __init boot_of_module(ulong r3, ulong r4, multiboot_info_t *mbi)
  18.110 -{
  18.111 -    static module_t mods[4];
  18.112 -    ulong mod0_start;
  18.113 -    ulong mod0_size;
  18.114 -    static const char * sepr[] = {" -- ", " || "};
  18.115 -    int sepr_index;
  18.116 -    extern char dom0_start[] __attribute__ ((weak));
  18.117 -    extern char dom0_size[] __attribute__ ((weak));
  18.118 -    const char *p = NULL;
  18.119 -    int mod;
  18.120 -    void *oft;
  18.121 -
  18.122 -    if ((r3 > 0) && (r4 > 0)) {
  18.123 -        /* was it handed to us in registers ? */
  18.124 -        mod0_start = r3;
  18.125 -        mod0_size = r4;
  18.126 -            of_printf("%s: Dom0 was loaded and found using r3/r4:"
  18.127 -                      "0x%lx[size 0x%lx]\n",
  18.128 -                      __func__, mod0_start, mod0_size);
  18.129 -    } else {
  18.130 -        /* see if it is in the boot params */
  18.131 -        p = strstr((char *)((ulong)mbi->cmdline), "dom0_start=");
  18.132 -        if ( p != NULL) {
  18.133 -            p += 11;
  18.134 -            mod0_start = simple_strtoul(p, NULL, 0);
  18.135 -
  18.136 -            p = strstr((char *)((ulong)mbi->cmdline), "dom0_size=");
  18.137 -            p += 10;
  18.138 -            mod0_size = simple_strtoul(p, NULL, 0);
  18.139 -            of_printf("%s: Dom0 was loaded and found using cmdline:"
  18.140 -                      "0x%lx[size 0x%lx]\n",
  18.141 -                      __func__, mod0_start, mod0_size);
  18.142 -        } else if ( ((ulong)dom0_start != 0) && ((ulong)dom0_size != 0) ) {
  18.143 -            /* was it linked in ? */
  18.144 -        
  18.145 -            mod0_start = (ulong)dom0_start;
  18.146 -            mod0_size = (ulong)dom0_size;
  18.147 -            of_printf("%s: Dom0 is linked in: 0x%lx[size 0x%lx]\n",
  18.148 -                      __func__, mod0_start, mod0_size);
  18.149 -        } else {
  18.150 -            mod0_start = (ulong)_end;
  18.151 -            mod0_size = 0;
  18.152 -            of_printf("%s: FYI Dom0 is unknown, will be caught later\n",
  18.153 -                      __func__);
  18.154 -        }
  18.155 -    }
  18.156 -
  18.157 -    if (mod0_size > 0) {
  18.158 -        const char *c = (const char *)mod0_start;
  18.159 -
  18.160 -        of_printf("mod0: %o %c %c %c\n", c[0], c[1], c[2], c[3]);
  18.161 -    }
  18.162 -
  18.163 -    mod = 0;
  18.164 -    mods[mod].mod_start = mod0_start;
  18.165 -    mods[mod].mod_end = mod0_start + mod0_size;
  18.166 -
  18.167 -    of_printf("%s: dom0 mod @ 0x%016x[0x%x]\n", __func__,
  18.168 -              mods[mod].mod_start, mods[mod].mod_end);
  18.169 -
  18.170 -    /* look for delimiter: "--" or "||" */
  18.171 -    for (sepr_index = 0; sepr_index < ARRAY_SIZE(sepr); sepr_index++){
  18.172 -        p = strstr((char *)(ulong)mbi->cmdline, sepr[sepr_index]);
  18.173 -        if (p != NULL)
  18.174 -            break;
  18.175 -    }
  18.176 -
  18.177 -    if (p != NULL) {
  18.178 -        /* Xen proper should never know about the dom0 args.  */
  18.179 -        *(char *)p = '\0';
  18.180 -        p += strlen(sepr[sepr_index]);
  18.181 -        mods[mod].string = (u32)(ulong)p;
  18.182 -        of_printf("%s: dom0 mod string: %s\n", __func__, p);
  18.183 -    }
  18.184 -
  18.185 -    ++mod;
  18.186 -    if (boot_of_rtas(&mods[mod], mbi))
  18.187 -        ++mod;
  18.188 -
  18.189 -    oft = boot_of_devtree(&mods[mod], mbi);
  18.190 -    if (oft == NULL)
  18.191 -        of_panic("%s: boot_of_devtree failed\n", __func__);
  18.192 -
  18.193 -    ++mod;
  18.194 -
  18.195 -    mbi->flags |= MBI_MODULES;
  18.196 -    mbi->mods_count = mod;
  18.197 -    mbi->mods_addr = (u32)mods;
  18.198 +    oftree = (ulong)oft;
  18.199 +    oftree = (ulong)oft + oft_sz;
  18.200 +    oftree_len = oft_sz; 
  18.201  
  18.202      return oft;
  18.203  }
  18.204 @@ -1327,16 +1207,20 @@ static int __init boot_of_cpus(void)
  18.205      return 1;
  18.206  }
  18.207  
  18.208 -multiboot_info_t __init *boot_of_init(
  18.209 -        ulong r3, ulong r4, ulong vec, ulong r6, ulong r7, ulong orig_msr)
  18.210 +void __init boot_of_init(ulong vec, ulong orig_msr)
  18.211  {
  18.212 -    static multiboot_info_t mbi;
  18.213 -    void *oft;
  18.214      int r;
  18.215  
  18.216      of_vec = vec;
  18.217      of_msr = orig_msr;
  18.218  
  18.219 +    if (is_kernel(vec)) {
  18.220 +        of_panic("Hmm.. OF[0x%lx] seems to have stepped on our image "
  18.221 +                "that ranges: %p .. %p.\n",
  18.222 +                vec, _start, _end);
  18.223 +    }
  18.224 +    of_printf("%s: _start %p _end %p\n", __func__, _start, _end);
  18.225 +
  18.226      bof_chosen = of_finddevice("/chosen");
  18.227      of_getprop(bof_chosen, "stdout", &of_out, sizeof (of_out));
  18.228  
  18.229 @@ -1346,32 +1230,20 @@ multiboot_info_t __init *boot_of_init(
  18.230                xen_compile_by(), xen_compile_domain(),
  18.231                xen_compiler(), xen_compile_date());
  18.232  
  18.233 -    of_printf("%s args: 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx\n"
  18.234 -            "boot msr: 0x%lx\n",
  18.235 -            __func__,
  18.236 -            r3, r4, vec, r6, r7, orig_msr);
  18.237 -
  18.238 -    if (is_kernel(vec)) {
  18.239 -        of_panic("Hmm.. OF[0x%lx] seems to have stepped on our image "
  18.240 -                "that ranges: %p .. %p.\n",
  18.241 -                vec, _start, _end);
  18.242 -    }
  18.243 -    of_printf("%s: _start %p _end %p 0x%lx\n", __func__, _start, _end, r6);
  18.244 -
  18.245      boot_of_fix_maple();
  18.246      r = boot_of_mem_init();
  18.247      if (r == 0)
  18.248          of_panic("failure to initialize memory allocator");
  18.249 -    boot_of_bootargs(&mbi);
  18.250 -    oft = boot_of_module(r3, r4, &mbi);
  18.251 +
  18.252 +    boot_of_rtas();
  18.253      boot_of_cpus();
  18.254 -    boot_of_serial(oft);
  18.255 +}
  18.256  
  18.257 +void __init boot_of_finish(void)
  18.258 +{
  18.259      /* end of OF */
  18.260      of_printf("Quiescing Open Firmware ...\n");
  18.261      of_call("quiesce", 0, 0, NULL);
  18.262 -
  18.263 -    return &mbi;
  18.264  }
  18.265  
  18.266  /*
    19.1 --- a/xen/arch/powerpc/domain.c	Wed Aug 01 09:40:58 2007 -0600
    19.2 +++ b/xen/arch/powerpc/domain.c	Wed Aug 01 16:40:30 2007 -0600
    19.3 @@ -29,7 +29,7 @@
    19.4  #include <xen/domain.h>
    19.5  #include <xen/console.h>
    19.6  #include <xen/shutdown.h>
    19.7 -#include <xen/shadow.h>
    19.8 +#include <xen/paging.h>
    19.9  #include <xen/mm.h>
   19.10  #include <xen/softirq.h>
   19.11  #include <asm/htab.h>
    20.1 --- a/xen/arch/powerpc/domain_build.c	Wed Aug 01 09:40:58 2007 -0600
    20.2 +++ b/xen/arch/powerpc/domain_build.c	Wed Aug 01 16:40:30 2007 -0600
    20.3 @@ -26,10 +26,9 @@
    20.4  #include <xen/init.h>
    20.5  #include <xen/ctype.h>
    20.6  #include <xen/iocap.h>
    20.7 -#include <xen/shadow.h>
    20.8  #include <xen/domain.h>
    20.9  #include <xen/version.h>
   20.10 -#include <xen/shadow.h>
   20.11 +#include <xen/paging.h>
   20.12  #include <asm/processor.h>
   20.13  #include <asm/platform.h>
   20.14  #include <asm/papr.h>
    21.1 --- a/xen/arch/powerpc/domctl.c	Wed Aug 01 09:40:58 2007 -0600
    21.2 +++ b/xen/arch/powerpc/domctl.c	Wed Aug 01 16:40:30 2007 -0600
    21.3 @@ -25,7 +25,7 @@
    21.4  #include <xen/sched.h>
    21.5  #include <xen/domain.h>
    21.6  #include <xen/guest_access.h>
    21.7 -#include <xen/shadow.h>
    21.8 +#include <xen/paging.h>
    21.9  #include <public/xen.h>
   21.10  #include <public/domctl.h>
   21.11  #include <public/sysctl.h>
    22.1 --- a/xen/arch/powerpc/exceptions.h	Wed Aug 01 09:40:58 2007 -0600
    22.2 +++ b/xen/arch/powerpc/exceptions.h	Wed Aug 01 16:40:30 2007 -0600
    22.3 @@ -33,9 +33,6 @@ extern void init_IRQ(void);
    22.4  extern void ack_APIC_irq(void);
    22.5  extern int ioapic_guest_read(unsigned long physbase, unsigned int reg, u32 *pval);
    22.6  extern int ioapic_guest_write(unsigned long physbase, unsigned int reg, u32 val);
    22.7 -extern void __start_xen_ppc(
    22.8 -    ulong r3, ulong r4, ulong r5, ulong r6, ulong r7, ulong orig_msr);
    22.9 -extern  multiboot_info_t *boot_of_init(ulong r3, ulong r4, ulong vec, ulong r6, ulong r7, ulong orig_msr);
   22.10  
   22.11  extern void do_timer(struct cpu_user_regs *regs);
   22.12  extern void do_dec(struct cpu_user_regs *regs);
    23.1 --- a/xen/arch/powerpc/memory.c	Wed Aug 01 09:40:58 2007 -0600
    23.2 +++ b/xen/arch/powerpc/memory.c	Wed Aug 01 16:40:30 2007 -0600
    23.3 @@ -21,6 +21,7 @@
    23.4  #include <xen/sched.h>
    23.5  #include <xen/mm.h>
    23.6  #include <xen/numa.h>
    23.7 +#include <asm/boot.h>
    23.8  #include "of-devtree.h"
    23.9  #include "oftree.h"
   23.10  #include "rtas.h"
   23.11 @@ -116,7 +117,7 @@ static void ofd_walk_mem(void *m, walk_m
   23.12      }
   23.13  }
   23.14  
   23.15 -void memory_init(module_t *mod, int mcount)
   23.16 +void memory_init(void)
   23.17  {
   23.18      ulong eomem;
   23.19      ulong bitmap_start = ~0UL;
    24.1 --- a/xen/arch/powerpc/mm.c	Wed Aug 01 09:40:58 2007 -0600
    24.2 +++ b/xen/arch/powerpc/mm.c	Wed Aug 01 16:40:30 2007 -0600
    24.3 @@ -22,7 +22,7 @@
    24.4  
    24.5  #include <xen/config.h>
    24.6  #include <xen/mm.h>
    24.7 -#include <xen/shadow.h>
    24.8 +#include <xen/paging.h>
    24.9  #include <xen/kernel.h>
   24.10  #include <xen/sched.h>
   24.11  #include <xen/perfc.h>
    25.1 --- a/xen/arch/powerpc/oftree.h	Wed Aug 01 09:40:58 2007 -0600
    25.2 +++ b/xen/arch/powerpc/oftree.h	Wed Aug 01 16:40:30 2007 -0600
    25.3 @@ -13,7 +13,7 @@
    25.4   * along with this program; if not, write to the Free Software
    25.5   * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    25.6   *
    25.7 - * Copyright (C) IBM Corp. 2005
    25.8 + * Copyright IBM Corp. 2005
    25.9   *
   25.10   * Authors: Jimi Xenidis <jimix@watson.ibm.com>
   25.11   */
   25.12 @@ -35,6 +35,4 @@ extern void ofd_memory_props(void *m, st
   25.13  extern int firmware_image_start[0];
   25.14  extern int firmware_image_size[0];
   25.15  
   25.16 -extern void memory_init(module_t *mod, int mcount);
   25.17 -
   25.18  #endif  /* #ifndef _OFTREE_H */
    26.1 --- a/xen/arch/powerpc/setup.c	Wed Aug 01 09:40:58 2007 -0600
    26.2 +++ b/xen/arch/powerpc/setup.c	Wed Aug 01 16:40:30 2007 -0600
    26.3 @@ -25,7 +25,7 @@
    26.4  #include <xen/lib.h>
    26.5  #include <xen/cpumask.h>
    26.6  #include <xen/sched.h>
    26.7 -#include <xen/multiboot.h>
    26.8 +#include <xen/multiboot2.h>
    26.9  #include <xen/serial.h>
   26.10  #include <xen/softirq.h>
   26.11  #include <xen/console.h>
   26.12 @@ -48,6 +48,7 @@
   26.13  #include <asm/delay.h>
   26.14  #include <asm/percpu.h>
   26.15  #include <asm/io.h>
   26.16 +#include <asm/boot.h>
   26.17  #include "exceptions.h"
   26.18  #include "of-devtree.h"
   26.19  #include "oftree.h"
   26.20 @@ -79,6 +80,17 @@ ulong oftree;
   26.21  ulong oftree_len;
   26.22  ulong oftree_end;
   26.23  
   26.24 +/* linked-in dom0: */
   26.25 +extern char dom0_start[] __attribute__ ((weak));
   26.26 +extern char dom0_size[] __attribute__ ((weak));
   26.27 +
   26.28 +char *xen_cmdline;
   26.29 +char *dom0_cmdline;
   26.30 +ulong dom0_addr;
   26.31 +ulong dom0_len;
   26.32 +ulong initrd_start;
   26.33 +ulong initrd_len;
   26.34 +
   26.35  uint cpu_hard_id[NR_CPUS] __initdata;
   26.36  cpumask_t cpu_present_map;
   26.37  
   26.38 @@ -286,21 +298,15 @@ void secondary_cpu_init(int cpuid, unsig
   26.39      panic("should never get here\n");
   26.40  }
   26.41  
   26.42 -static void __init __start_xen(multiboot_info_t *mbi)
   26.43 +static void __init __start_xen(void)
   26.44  {
   26.45 -    char *cmdline;
   26.46 -    module_t *mod = (module_t *)((ulong)mbi->mods_addr);
   26.47 -    ulong dom0_start, dom0_len;
   26.48 -    ulong initrd_start, initrd_len;
   26.49 -
   26.50      memcpy(0, exception_vectors, exception_vectors_end - exception_vectors);
   26.51      synchronize_caches(0, exception_vectors_end - exception_vectors);
   26.52  
   26.53      ticks_per_usec = timebase_freq / 1000000ULL;
   26.54  
   26.55      /* Parse the command-line options. */
   26.56 -    if ((mbi->flags & MBI_CMDLINE) && (mbi->cmdline != 0))
   26.57 -        cmdline_parse(__va((ulong)mbi->cmdline));
   26.58 +    cmdline_parse(xen_cmdline);
   26.59  
   26.60      /* we need to be able to identify this CPU early on */
   26.61      init_boot_cpu();
   26.62 @@ -313,32 +319,20 @@ static void __init __start_xen(multiboot
   26.63      serial_init_preirq();
   26.64  
   26.65      init_console();
   26.66 -    /* let synchronize until we really get going */
   26.67 -    console_start_sync();
   26.68 -
   26.69 -    /* Check that we have at least one Multiboot module. */
   26.70 -    if (!(mbi->flags & MBI_MODULES) || (mbi->mods_count == 0)) {
   26.71 -        panic("FATAL ERROR: Require at least one Multiboot module.\n");
   26.72 -    }
   26.73 -
   26.74 -    /* OF dev tree is the last module */
   26.75 -    oftree = mod[mbi->mods_count-1].mod_start;
   26.76 -    oftree_end = mod[mbi->mods_count-1].mod_end;
   26.77 -    oftree_len = oftree_end - oftree;
   26.78 +    console_start_sync(); /* Stay synchronous for early debugging. */
   26.79  
   26.80 -    /* remove it from consideration */
   26.81 -    mod[mbi->mods_count-1].mod_start = 0;
   26.82 -    mod[mbi->mods_count-1].mod_end = 0;
   26.83 -    --mbi->mods_count;
   26.84 +    rtas_init((void *)oftree);
   26.85  
   26.86 -    if (rtas_entry) {
   26.87 -        rtas_init((void *)oftree);
   26.88 -        /* remove rtas module from consideration */
   26.89 -        mod[mbi->mods_count-1].mod_start = 0;
   26.90 -        mod[mbi->mods_count-1].mod_end = 0;
   26.91 -        --mbi->mods_count;
   26.92 -    }
   26.93 -    memory_init(mod, mbi->mods_count);
   26.94 +    memory_init();
   26.95 +
   26.96 +    printk("xen_cmdline:  %016lx\n", (ulong)xen_cmdline);
   26.97 +    printk("dom0_cmdline: %016lx\n", (ulong)dom0_cmdline);
   26.98 +    printk("dom0_addr:    %016lx\n", (ulong)dom0_addr);
   26.99 +    printk("dom0_len:     %016lx\n", (ulong)dom0_len);
  26.100 +    printk("initrd_start: %016lx\n", (ulong)initrd_start);
  26.101 +    printk("initrd_len:   %016lx\n", (ulong)initrd_len);
  26.102 +
  26.103 +    printk("dom0: %016llx\n", *(unsigned long long *)dom0_addr);
  26.104  
  26.105  #ifdef OF_DEBUG
  26.106      key_ofdump(0);
  26.107 @@ -382,30 +376,22 @@ static void __init __start_xen(multiboot
  26.108  
  26.109      dom0->is_privileged = 1;
  26.110  
  26.111 -    cmdline = (char *)(mod[0].string ? __va((ulong)mod[0].string) : NULL);
  26.112 -
  26.113      /* scrub_heap_pages() requires IRQs enabled, and we're post IRQ setup... */
  26.114      local_irq_enable();
  26.115      /* Scrub RAM that is still free and so may go to an unprivileged domain. */
  26.116      scrub_heap_pages();
  26.117  
  26.118 -    dom0_start = mod[0].mod_start;
  26.119 -    dom0_len = mod[0].mod_end - mod[0].mod_start;
  26.120 -    if (mbi->mods_count > 1) {
  26.121 -        initrd_start = mod[1].mod_start;
  26.122 -        initrd_len = mod[1].mod_end - mod[1].mod_start;
  26.123 -    } else {
  26.124 -        initrd_start = 0;
  26.125 -        initrd_len = 0;
  26.126 -    }
  26.127 -    if (construct_dom0(dom0, dom0_start, dom0_len,
  26.128 +    if ((dom0_addr == 0) || (dom0_len == 0))
  26.129 +        panic("No domain 0 found.\n");
  26.130 +
  26.131 +    if (construct_dom0(dom0, dom0_addr, dom0_len,
  26.132                         initrd_start, initrd_len,
  26.133 -                       cmdline) != 0) {
  26.134 +                       dom0_cmdline) != 0) {
  26.135          panic("Could not set up DOM0 guest OS\n");
  26.136      }
  26.137  
  26.138 -    init_xenheap_pages(ALIGN_UP(dom0_start, PAGE_SIZE),
  26.139 -                       ALIGN_DOWN(dom0_start + dom0_len, PAGE_SIZE));
  26.140 +    init_xenheap_pages(ALIGN_UP(dom0_addr, PAGE_SIZE),
  26.141 +                       ALIGN_DOWN(dom0_addr + dom0_len, PAGE_SIZE));
  26.142      if (initrd_start)
  26.143          init_xenheap_pages(ALIGN_UP(initrd_start, PAGE_SIZE),
  26.144                             ALIGN_DOWN(initrd_start + initrd_len, PAGE_SIZE));
  26.145 @@ -426,25 +412,74 @@ static void __init __start_xen(multiboot
  26.146      startup_cpu_idle_loop();
  26.147  }
  26.148  
  26.149 +static void ofd_bootargs(void)
  26.150 +{
  26.151 +    static const char *sepr[] = {" -- ", " || "};
  26.152 +    char *p;
  26.153 +    ofdn_t chosen;
  26.154 +    int sepr_index;
  26.155 +    int rc;
  26.156 +
  26.157 +    if (builtin_cmdline[0] == '\0') {
  26.158 +        chosen = ofd_node_find((void *)oftree, "/chosen");
  26.159 +        rc = ofd_getprop((void *)oftree, chosen, "bootargs", builtin_cmdline,
  26.160 +                         CONFIG_CMDLINE_SIZE);
  26.161 +    }
  26.162 +
  26.163 +    /* look for delimiter: "--" or "||" */
  26.164 +    for (sepr_index = 0; sepr_index < ARRAY_SIZE(sepr); sepr_index++){
  26.165 +        p = strstr(builtin_cmdline, sepr[sepr_index]);
  26.166 +        if (p != NULL) {
  26.167 +            /* Xen proper should never know about the dom0 args.  */
  26.168 +            *p = '\0';
  26.169 +            p += strlen(sepr[sepr_index]);
  26.170 +            dom0_cmdline = p;
  26.171 +            break;
  26.172 +        }
  26.173 +    }
  26.174 +
  26.175 +    xen_cmdline = builtin_cmdline;
  26.176 +}
  26.177 +
  26.178 +void __init __start_xen_ppc(ulong, ulong, ulong, ulong, ulong, ulong);
  26.179  void __init __start_xen_ppc(
  26.180      ulong r3, ulong r4, ulong r5, ulong r6, ulong r7, ulong orig_msr)
  26.181  {
  26.182 -    multiboot_info_t *mbi = NULL;
  26.183 -
  26.184      /* clear bss */
  26.185      memset(__bss_start, 0, (ulong)_end - (ulong)__bss_start);
  26.186  
  26.187 -    if (r5 > 0) {
  26.188 -        /* we were booted by OpenFirmware */
  26.189 -        mbi = boot_of_init(r3, r4, r5, r6, r7, orig_msr);
  26.190 -
  26.191 +    if (r5) {
  26.192 +        /* We came from Open Firmware. */
  26.193 +        boot_of_init(r5, orig_msr);
  26.194 +        oftree = (ulong)boot_of_devtree(); /* Copy the device tree. */
  26.195 +        /* Use the device tree to find the Xen console. */
  26.196 +        boot_of_serial((void *)oftree);
  26.197 +        boot_of_finish(); /* End firmware. */
  26.198      } else {
  26.199 -        /* booted by someone else that hopefully has a trap handler */
  26.200 +        /* XXX handle flat device tree here */
  26.201          __builtin_trap();
  26.202      }
  26.203  
  26.204 -    __start_xen(mbi);
  26.205 +    ofd_bootargs();
  26.206  
  26.207 +    if (r3 == MB2_BOOTLOADER_MAGIC) {
  26.208 +        /* Get dom0 info from multiboot structures. */
  26.209 +        parse_multiboot(r4);
  26.210 +    }
  26.211 +
  26.212 +    if ((dom0_len == 0) && r3 && r4) {
  26.213 +        /* Maybe dom0's location handed to us in registers. */
  26.214 +        dom0_addr = r3;
  26.215 +        dom0_len = r4;
  26.216 +    }
  26.217 +
  26.218 +    if (dom0_len == 0) {
  26.219 +        /* Dom0 had better be built in. */
  26.220 +        dom0_addr = (ulong)dom0_start;
  26.221 +        dom0_len = (ulong)dom0_size;
  26.222 +    }
  26.223 +
  26.224 +    __start_xen();
  26.225  }
  26.226  
  26.227  extern void arch_get_xen_caps(xen_capabilities_info_t *info);
    27.1 --- a/xen/arch/powerpc/shadow.c	Wed Aug 01 09:40:58 2007 -0600
    27.2 +++ b/xen/arch/powerpc/shadow.c	Wed Aug 01 16:40:30 2007 -0600
    27.3 @@ -20,7 +20,7 @@
    27.4  
    27.5  #include <xen/config.h>
    27.6  #include <xen/types.h>
    27.7 -#include <xen/shadow.h>
    27.8 +#include <xen/paging.h>
    27.9  
   27.10  static ulong htab_calc_sdr1(ulong htab_addr, ulong log_htab_size)
   27.11  {
    28.1 --- a/xen/arch/powerpc/sysctl.c	Wed Aug 01 09:40:58 2007 -0600
    28.2 +++ b/xen/arch/powerpc/sysctl.c	Wed Aug 01 16:40:30 2007 -0600
    28.3 @@ -24,7 +24,6 @@
    28.4  #include <xen/nodemask.h>
    28.5  #include <xen/sched.h>
    28.6  #include <xen/guest_access.h>
    28.7 -#include <xen/shadow.h>
    28.8  #include <public/xen.h>
    28.9  #include <public/domctl.h>
   28.10  #include <public/sysctl.h>
    29.1 --- a/xen/arch/x86/acpi/boot.c	Wed Aug 01 09:40:58 2007 -0600
    29.2 +++ b/xen/arch/x86/acpi/boot.c	Wed Aug 01 16:40:30 2007 -0600
    29.3 @@ -371,12 +371,19 @@ extern u32 pmtmr_ioport;
    29.4  
    29.5  #ifdef CONFIG_ACPI_SLEEP
    29.6  /* Get pm1x_cnt and pm1x_evt information for ACPI sleep */
    29.7 -static int __init
    29.8 +static void __init
    29.9  acpi_fadt_parse_sleep_info(struct fadt_descriptor_rev2 *fadt)
   29.10  {
   29.11 +	struct acpi_table_rsdp *rsdp;
   29.12 +	unsigned long rsdp_phys;
   29.13  	struct facs_descriptor_rev2 *facs = NULL;
   29.14  	uint64_t facs_pa;
   29.15  
   29.16 +	rsdp_phys = acpi_find_rsdp();
   29.17 +	if (!rsdp_phys || acpi_disabled)
   29.18 +		goto bad;
   29.19 +	rsdp = __va(rsdp_phys);
   29.20 +
   29.21  	if (fadt->revision >= FADT2_REVISION_ID) {
   29.22  		/* Sanity check on FADT Rev. 2 */
   29.23  		if ((fadt->xpm1a_cnt_blk.address_space_id !=
   29.24 @@ -432,8 +439,7 @@ acpi_fadt_parse_sleep_info(struct fadt_d
   29.25  			"FACS is shorter than ACPI spec allow: 0x%x",
   29.26  			facs->length);
   29.27  
   29.28 -	if ((acpi_rsdp_rev < 2) ||
   29.29 -	    (facs->length < 32)) {
   29.30 +	if ((rsdp->revision < 2) || (facs->length < 32)) {
   29.31  		acpi_sinfo.wakeup_vector = facs_pa + 
   29.32  			offsetof(struct facs_descriptor_rev2,
   29.33  				 firmware_waking_vector);
   29.34 @@ -451,10 +457,9 @@ acpi_fadt_parse_sleep_info(struct fadt_d
   29.35  		acpi_sinfo.pm1a_cnt, acpi_sinfo.pm1b_cnt,
   29.36  		acpi_sinfo.pm1a_evt, acpi_sinfo.pm1b_cnt,
   29.37  		acpi_sinfo.wakeup_vector, acpi_sinfo.vector_width);
   29.38 -	return 0;
   29.39 +	return;
   29.40  bad:
   29.41  	memset(&acpi_sinfo, 0, sizeof(acpi_sinfo));
   29.42 -	return 0;
   29.43  }
   29.44  #endif
   29.45  
    30.1 --- a/xen/arch/x86/domain_build.c	Wed Aug 01 09:40:58 2007 -0600
    30.2 +++ b/xen/arch/x86/domain_build.c	Wed Aug 01 16:40:30 2007 -0600
    30.3 @@ -316,6 +316,9 @@ int __init construct_dom0(
    30.4             parms.pae       ? ", PAE"  : "",
    30.5             elf_msb(&elf)   ? "msb"    : "lsb",
    30.6             elf.pstart, elf.pend);
    30.7 +    if ( parms.bsd_symtab )
    30.8 +        printk(" Dom0 symbol map 0x%" PRIx64 " -> 0x%" PRIx64 "\n",
    30.9 +               elf.sstart, elf.send);
   30.10  
   30.11      if ( !compatible )
   30.12      {
   30.13 @@ -385,7 +388,7 @@ int __init construct_dom0(
   30.14      v_start          = parms.virt_base;
   30.15      vkern_start      = parms.virt_kstart;
   30.16      vkern_end        = parms.virt_kend;
   30.17 -    vinitrd_start    = round_pgup(vkern_end);
   30.18 +    vinitrd_start    = round_pgup(parms.virt_end);
   30.19      vinitrd_end      = vinitrd_start + initrd_len;
   30.20      vphysmap_start   = round_pgup(vinitrd_end);
   30.21      vphysmap_end     = vphysmap_start + (nr_pages * (!is_pv_32on64_domain(d) ?
   30.22 @@ -795,7 +798,7 @@ int __init construct_dom0(
   30.23  
   30.24      /* Copy the OS image and free temporary buffer. */
   30.25      elf.dest = (void*)vkern_start;
   30.26 -    elf_load_binary(&elf);
   30.27 +    elf_xen_dom_load_binary(&elf, &parms);
   30.28  
   30.29      if ( UNSET_ADDR != parms.virt_hypercall )
   30.30      {
    31.1 --- a/xen/arch/x86/hvm/instrlen.c	Wed Aug 01 09:40:58 2007 -0600
    31.2 +++ b/xen/arch/x86/hvm/instrlen.c	Wed Aug 01 16:40:30 2007 -0600
    31.3 @@ -9,14 +9,6 @@
    31.4   * x86_emulate.c.  Used for MMIO.
    31.5   */
    31.6  
    31.7 -/*
    31.8 - * TODO: The way in which we use hvm_instruction_length is very inefficient as
    31.9 - * it now stands. It will be worthwhile to return the actual instruction buffer
   31.10 - * along with the instruction length since one of the reasons we are getting
   31.11 - * the instruction length is to know how many instruction bytes we need to
   31.12 - * fetch.
   31.13 - */
   31.14 -
   31.15  #include <xen/config.h>
   31.16  #include <xen/sched.h>
   31.17  #include <xen/mm.h>
   31.18 @@ -194,31 +186,51 @@ static uint8_t twobyte_table[256] = {
   31.19  /* 
   31.20   * insn_fetch - fetch the next byte from instruction stream
   31.21   */
   31.22 -#define insn_fetch()                                                    \
   31.23 -({ uint8_t _x;                                                          \
   31.24 -   if ( length >= 15 )                                                  \
   31.25 -       return -1;                                                       \
   31.26 -   if ( inst_copy_from_guest(&_x, pc, 1) != 1 ) {                       \
   31.27 -       gdprintk(XENLOG_WARNING,                                         \
   31.28 -                "Cannot read from address %lx (eip %lx, mode %d)\n",    \
   31.29 -                pc, org_pc, address_bytes);                             \
   31.30 -       return -1;                                                       \
   31.31 -   }                                                                    \
   31.32 -   pc += 1;                                                             \
   31.33 -   length += 1;                                                         \
   31.34 -   _x;                                                                  \
   31.35 +#define insn_fetch()                                                      \
   31.36 +({ uint8_t _x;                                                            \
   31.37 +   if ( length >= 15 )                                                    \
   31.38 +       return -1;                                                         \
   31.39 +   if ( inst_copy_from_guest(&_x, pc, 1) != 1 ) {                         \
   31.40 +       unsigned long err;                                                 \
   31.41 +       struct segment_register cs;                                        \
   31.42 +       gdprintk(XENLOG_WARNING,                                           \
   31.43 +                "Cannot read from address %lx (eip %lx, mode %d)\n",      \
   31.44 +                pc, org_pc, address_bytes);                               \
   31.45 +       err = 0; /* Must be not-present: we don't enforce reserved bits */ \
   31.46 +       if ( hvm_nx_enabled(current) )                                     \
   31.47 +           err |= PFEC_insn_fetch;                                        \
   31.48 +       hvm_get_segment_register(current, x86_seg_cs, &cs);                \
   31.49 +       if ( cs.attr.fields.dpl != 0 )                                     \
   31.50 +           err |= PFEC_user_mode;                                         \
   31.51 +       hvm_inject_exception(TRAP_page_fault, err, pc);                    \
   31.52 +       return -1;                                                         \
   31.53 +   }                                                                      \
   31.54 +   if ( buf )                                                             \
   31.55 +       buf[length] = _x;                                                  \
   31.56 +   length += 1;                                                           \
   31.57 +   pc += 1;                                                               \
   31.58 +   _x;                                                                    \
   31.59  })
   31.60  
   31.61 +#define insn_skip(_n) do {                      \
   31.62 +    int _i;                                     \
   31.63 +    for ( _i = 0; _i < (_n); _i++) {            \
   31.64 +        (void) insn_fetch();                    \
   31.65 +    }                                           \
   31.66 +} while (0)
   31.67 +
   31.68  /**
   31.69 - * hvm_instruction_length - returns the current instructions length
   31.70 + * hvm_instruction_fetch - read the current instruction and return its length
   31.71   *
   31.72   * @org_pc: guest instruction pointer
   31.73 - * @mode: guest operating mode
   31.74 + * @address_bytes: guest address width
   31.75 + * @buf: (optional) buffer to load actual instruction bytes into
   31.76   *
   31.77 - * EXTERNAL this routine calculates the length of the current instruction
   31.78 - * pointed to by org_pc.  The guest state is _not_ changed by this routine.
   31.79 + * Doesn't increment the guest's instruction pointer, but may
   31.80 + * issue faults to the guest.  Returns -1 on failure.
   31.81   */
   31.82 -int hvm_instruction_length(unsigned long org_pc, int address_bytes)
   31.83 +int hvm_instruction_fetch(unsigned long org_pc, int address_bytes,
   31.84 +                          unsigned char *buf)
   31.85  {
   31.86      uint8_t b, d, twobyte = 0, rex_prefix = 0, modrm_reg = 0;
   31.87      unsigned int op_default, op_bytes, ad_default, ad_bytes, tmp;
   31.88 @@ -317,18 +329,13 @@ done_prefixes:
   31.89              {
   31.90              case 0:
   31.91                  if ( modrm_rm == 6 ) 
   31.92 -                {
   31.93 -                    length += 2;
   31.94 -                    pc += 2; /* skip disp16 */
   31.95 -                }
   31.96 +                    insn_skip(2); /* skip disp16 */
   31.97                  break;
   31.98              case 1:
   31.99 -                length += 1;
  31.100 -                pc += 1; /* skip disp8 */
  31.101 +                insn_skip(1); /* skip disp8 */
  31.102                  break;
  31.103              case 2:
  31.104 -                length += 2;
  31.105 -                pc += 2; /* skip disp16 */
  31.106 +                insn_skip(2); /* skip disp16 */
  31.107                  break;
  31.108              }
  31.109          }
  31.110 @@ -340,33 +347,19 @@ done_prefixes:
  31.111              case 0:
  31.112                  if ( (modrm_rm == 4) && 
  31.113                       ((insn_fetch() & 7) == 5) )
  31.114 -                {
  31.115 -                    length += 4;
  31.116 -                    pc += 4; /* skip disp32 specified by SIB.base */
  31.117 -                }
  31.118 +                    insn_skip(4); /* skip disp32 specified by SIB.base */
  31.119                  else if ( modrm_rm == 5 )
  31.120 -                {
  31.121 -                    length += 4;
  31.122 -                    pc += 4; /* skip disp32 */
  31.123 -                }
  31.124 +                    insn_skip(4); /* skip disp32 */
  31.125                  break;
  31.126              case 1:
  31.127                  if ( modrm_rm == 4 )
  31.128 -                {
  31.129 -                    length += 1;
  31.130 -                    pc += 1;
  31.131 -                }
  31.132 -                length += 1;
  31.133 -                pc += 1; /* skip disp8 */
  31.134 +                    insn_skip(1);
  31.135 +                insn_skip(1); /* skip disp8 */
  31.136                  break;
  31.137              case 2:
  31.138                  if ( modrm_rm == 4 )
  31.139 -                {
  31.140 -                    length += 1;
  31.141 -                    pc += 1;
  31.142 -                }
  31.143 -                length += 4;
  31.144 -                pc += 4; /* skip disp32 */
  31.145 +                    insn_skip(1);
  31.146 +                insn_skip(4); /* skip disp32 */
  31.147                  break;
  31.148              }
  31.149          }
  31.150 @@ -387,12 +380,10 @@ done_prefixes:
  31.151          tmp = (d & ByteOp) ? 1 : op_bytes;
  31.152          if ( tmp == 8 ) tmp = 4;
  31.153          /* NB. Immediates are sign-extended as necessary. */
  31.154 -        length += tmp;
  31.155 -        pc += tmp;
  31.156 +        insn_skip(tmp);
  31.157          break;
  31.158      case SrcImmByte:
  31.159 -        length += 1;
  31.160 -        pc += 1;
  31.161 +        insn_skip(1);
  31.162          break;
  31.163      }
  31.164  
  31.165 @@ -402,8 +393,7 @@ done_prefixes:
  31.166      switch ( b )
  31.167      {
  31.168      case 0xa0 ... 0xa3: /* mov */
  31.169 -        length += ad_bytes;
  31.170 -        pc += ad_bytes; /* skip src/dst displacement */
  31.171 +        insn_skip(ad_bytes); /* skip src/dst displacement */
  31.172          break;
  31.173      case 0xf6 ... 0xf7: /* Grp3 */
  31.174          switch ( modrm_reg )
  31.175 @@ -412,8 +402,7 @@ done_prefixes:
  31.176              /* Special case in Grp3: test has an immediate source operand. */
  31.177              tmp = (d & ByteOp) ? 1 : op_bytes;
  31.178              if ( tmp == 8 ) tmp = 4;
  31.179 -            length += tmp;
  31.180 -            pc += tmp;
  31.181 +            insn_skip(tmp);
  31.182              break;
  31.183          }
  31.184          break;
    32.1 --- a/xen/arch/x86/hvm/platform.c	Wed Aug 01 09:40:58 2007 -0600
    32.2 +++ b/xen/arch/x86/hvm/platform.c	Wed Aug 01 16:40:30 2007 -0600
    32.3 @@ -1041,17 +1041,13 @@ void handle_mmio(unsigned long gpa)
    32.4          /* real or vm86 modes */
    32.5          address_bytes = 2;
    32.6      inst_addr = hvm_get_segment_base(v, x86_seg_cs) + regs->eip;
    32.7 -    inst_len = hvm_instruction_length(inst_addr, address_bytes);
    32.8 +    memset(inst, 0, MAX_INST_LEN);
    32.9 +    inst_len = hvm_instruction_fetch(inst_addr, address_bytes, inst);
   32.10      if ( inst_len <= 0 )
   32.11      {
   32.12 -        printk("handle_mmio: failed to get instruction length\n");
   32.13 -        domain_crash_synchronous();
   32.14 -    }
   32.15 -
   32.16 -    memset(inst, 0, MAX_INST_LEN);
   32.17 -    if ( inst_copy_from_guest(inst, inst_addr, inst_len) != inst_len ) {
   32.18 -        printk("handle_mmio: failed to copy instruction\n");
   32.19 -        domain_crash_synchronous();
   32.20 +        gdprintk(XENLOG_DEBUG, "handle_mmio: failed to get instruction\n");
   32.21 +        /* hvm_instruction_fetch() will have injected a #PF; get out now */
   32.22 +        return;
   32.23      }
   32.24  
   32.25      if ( mmio_decode(address_bytes, inst, mmio_op, &ad_size,
    33.1 --- a/xen/arch/x86/hvm/svm/intr.c	Wed Aug 01 09:40:58 2007 -0600
    33.2 +++ b/xen/arch/x86/hvm/svm/intr.c	Wed Aug 01 16:40:30 2007 -0600
    33.3 @@ -58,7 +58,7 @@ static void svm_inject_nmi(struct vcpu *
    33.4  
    33.5      event.bytes = 0;
    33.6      event.fields.v = 1;
    33.7 -    event.fields.type = EVENTTYPE_NMI;
    33.8 +    event.fields.type = X86_EVENTTYPE_NMI;
    33.9      event.fields.vector = 2;
   33.10  
   33.11      ASSERT(vmcb->eventinj.fields.v == 0);
   33.12 @@ -72,13 +72,33 @@ static void svm_inject_extint(struct vcp
   33.13  
   33.14      event.bytes = 0;
   33.15      event.fields.v = 1;
   33.16 -    event.fields.type = EVENTTYPE_INTR;
   33.17 +    event.fields.type = X86_EVENTTYPE_EXT_INTR;
   33.18      event.fields.vector = vector;
   33.19  
   33.20      ASSERT(vmcb->eventinj.fields.v == 0);
   33.21      vmcb->eventinj = event;
   33.22  }
   33.23      
   33.24 +static void enable_intr_window(struct vcpu *v, enum hvm_intack intr_source)
   33.25 +{
   33.26 +    struct vmcb_struct *vmcb = v->arch.hvm_svm.vmcb;
   33.27 +
   33.28 +    ASSERT(intr_source != hvm_intack_none);
   33.29 +
   33.30 +    /*
   33.31 +     * Create a dummy virtual interrupt to intercept as soon as the
   33.32 +     * guest can accept the real interrupt.
   33.33 +     *
   33.34 +     * TODO: Better NMI handling. We need a way to skip a MOV SS interrupt
   33.35 +     * shadow. This is hard to do without hardware support. We should also
   33.36 +     * track 'NMI blocking' from NMI injection until IRET. This can be done
   33.37 +     * quite easily in software by intercepting the unblocking IRET.
   33.38 +     */
   33.39 +    vmcb->general1_intercepts |= GENERAL1_INTERCEPT_VINTR;
   33.40 +    HVMTRACE_2D(INJ_VIRQ, v, 0x0, /*fake=*/ 1);
   33.41 +    svm_inject_dummy_vintr(v);
   33.42 +}
   33.43 +
   33.44  asmlinkage void svm_intr_assist(void) 
   33.45  {
   33.46      struct vcpu *v = current;
   33.47 @@ -86,21 +106,6 @@ asmlinkage void svm_intr_assist(void)
   33.48      enum hvm_intack intr_source;
   33.49      int intr_vector;
   33.50  
   33.51 -    /*
   33.52 -     * Previous event delivery caused this intercept?
   33.53 -     * This will happen if the injection is latched by the processor (hence
   33.54 -     * clearing vintr.fields.irq or eventinj.v) but then subsequently a fault
   33.55 -     * occurs (e.g., due to lack of shadow mapping of guest IDT or guest-kernel
   33.56 -     * stack).
   33.57 -     */
   33.58 -    if ( vmcb->exitintinfo.fields.v )
   33.59 -    {
   33.60 -        vmcb->eventinj = vmcb->exitintinfo;
   33.61 -        vmcb->exitintinfo.bytes = 0;
   33.62 -        HVMTRACE_1D(REINJ_VIRQ, v, intr_vector);
   33.63 -        return;
   33.64 -    }
   33.65 -
   33.66      /* Crank the handle on interrupt state. */
   33.67      pt_update_irq(v);
   33.68      hvm_set_callback_irq_level();
   33.69 @@ -111,32 +116,23 @@ asmlinkage void svm_intr_assist(void)
   33.70              return;
   33.71  
   33.72          /*
   33.73 -         * If the guest can't take an interrupt right now, create a 'fake'
   33.74 -         * virtual interrupt on to intercept as soon as the guest _can_ take
   33.75 -         * interrupts.  Do not obtain the next interrupt from the vlapic/pic
   33.76 -         * if unable to inject.
   33.77 -         *
   33.78 -         * Also do this if there is an injection already pending. This is
   33.79 -         * because the event delivery can arbitrarily delay the injection
   33.80 -         * of the vintr (for example, if the exception is handled via an
   33.81 -         * interrupt gate, hence zeroing RFLAGS.IF). In the meantime:
   33.82 -         * - the vTPR could be modified upwards, so we need to wait until the
   33.83 -         *   exception is delivered before we can safely decide that an
   33.84 -         *   interrupt is deliverable; and
   33.85 -         * - the guest might look at the APIC/PIC state, so we ought not to
   33.86 -         *   have cleared the interrupt out of the IRR.
   33.87 -         *
   33.88 -         * TODO: Better NMI handling. We need a way to skip a MOV SS interrupt
   33.89 -         * shadow. This is hard to do without hardware support. We should also
   33.90 -         * track 'NMI blocking' from NMI injection until IRET. This can be done
   33.91 -         * quite easily in software by intercepting the unblocking IRET.
   33.92 +         * Pending IRQs must be delayed if:
   33.93 +         * 1. An event is already pending. This is despite the fact that SVM
   33.94 +         *    provides a VINTR delivery method quite separate from the EVENTINJ
   33.95 +         *    mechanism. The event delivery can arbitrarily delay the injection
   33.96 +         *    of the vintr (for example, if the exception is handled via an
   33.97 +         *    interrupt gate, hence zeroing RFLAGS.IF). In the meantime:
   33.98 +         *    - the vTPR could be modified upwards, so we need to wait until
   33.99 +         *      the exception is delivered before we can safely decide that an
  33.100 +         *      interrupt is deliverable; and
  33.101 +         *    - the guest might look at the APIC/PIC state, so we ought not to
  33.102 +         *      have cleared the interrupt out of the IRR.
  33.103 +         * 2. The IRQ is masked.
  33.104           */
  33.105 -        if ( !hvm_interrupts_enabled(v, intr_source) ||
  33.106 -             vmcb->eventinj.fields.v )
  33.107 +        if ( unlikely(vmcb->eventinj.fields.v) ||
  33.108 +             !hvm_interrupts_enabled(v, intr_source) )
  33.109          {
  33.110 -            vmcb->general1_intercepts |= GENERAL1_INTERCEPT_VINTR;
  33.111 -            HVMTRACE_2D(INJ_VIRQ, v, 0x0, /*fake=*/ 1);
  33.112 -            svm_inject_dummy_vintr(v);
  33.113 +            enable_intr_window(v, intr_source);
  33.114              return;
  33.115          }
  33.116      } while ( !hvm_vcpu_ack_pending_irq(v, intr_source, &intr_vector) );
  33.117 @@ -151,6 +147,11 @@ asmlinkage void svm_intr_assist(void)
  33.118          svm_inject_extint(v, intr_vector);
  33.119          pt_intr_post(v, intr_vector, intr_source);
  33.120      }
  33.121 +
  33.122 +    /* Is there another IRQ to queue up behind this one? */
  33.123 +    intr_source = hvm_vcpu_has_pending_irq(v);
  33.124 +    if ( unlikely(intr_source != hvm_intack_none) )
  33.125 +        enable_intr_window(v, intr_source);
  33.126  }
  33.127  
  33.128  /*
    34.1 --- a/xen/arch/x86/hvm/svm/svm.c	Wed Aug 01 09:40:58 2007 -0600
    34.2 +++ b/xen/arch/x86/hvm/svm/svm.c	Wed Aug 01 16:40:30 2007 -0600
    34.3 @@ -71,8 +71,8 @@ static void *root_vmcb[NR_CPUS] __read_m
    34.4  /* hardware assisted paging bits */
    34.5  extern int opt_hap_enabled;
    34.6  
    34.7 -static void svm_inject_exception(struct vcpu *v, int trap, 
    34.8 -                                        int ev, int error_code)
    34.9 +static void svm_inject_exception(
   34.10 +    struct vcpu *v, int trap, int ev, int error_code)
   34.11  {
   34.12      eventinj_t event;
   34.13      struct vmcb_struct *vmcb = v->arch.hvm_svm.vmcb;
   34.14 @@ -84,13 +84,11 @@ static void svm_inject_exception(struct 
   34.15  
   34.16      event.bytes = 0;            
   34.17      event.fields.v = 1;
   34.18 -    event.fields.type = EVENTTYPE_EXCEPTION;
   34.19 +    event.fields.type = X86_EVENTTYPE_HW_EXCEPTION;
   34.20      event.fields.vector = trap;
   34.21      event.fields.ev = ev;
   34.22      event.fields.errorcode = error_code;
   34.23  
   34.24 -    ASSERT(vmcb->eventinj.fields.v == 0);
   34.25 -    
   34.26      vmcb->eventinj = event;
   34.27  }
   34.28  
   34.29 @@ -362,22 +360,15 @@ int svm_vmcb_save(struct vcpu *v, struct
   34.30      c->sysenter_esp = vmcb->sysenter_esp;
   34.31      c->sysenter_eip = vmcb->sysenter_eip;
   34.32  
   34.33 -    /* Save any event/interrupt that was being injected when we last exited. */
   34.34 -    if ( vmcb->exitintinfo.fields.v )
   34.35 +    c->pending_event = 0;
   34.36 +    c->error_code = 0;
   34.37 +    if ( vmcb->eventinj.fields.v &&
   34.38 +         hvm_event_needs_reinjection(vmcb->eventinj.fields.type,
   34.39 +                                     vmcb->eventinj.fields.vector) )
   34.40      {
   34.41 -        c->pending_event = vmcb->exitintinfo.bytes & 0xffffffff;
   34.42 -        c->error_code = vmcb->exitintinfo.fields.errorcode;
   34.43 -    }
   34.44 -    else if ( vmcb->eventinj.fields.v ) 
   34.45 -    {
   34.46 -        c->pending_event = vmcb->eventinj.bytes & 0xffffffff;
   34.47 +        c->pending_event = (uint32_t)vmcb->eventinj.bytes;
   34.48          c->error_code = vmcb->eventinj.fields.errorcode;
   34.49      }
   34.50 -    else 
   34.51 -    {
   34.52 -        c->pending_event = 0;
   34.53 -        c->error_code = 0;
   34.54 -    }
   34.55  
   34.56      return 1;
   34.57  }
   34.58 @@ -495,11 +486,11 @@ int svm_vmcb_restore(struct vcpu *v, str
   34.59      vmcb->sysenter_esp = c->sysenter_esp;
   34.60      vmcb->sysenter_eip = c->sysenter_eip;
   34.61  
   34.62 -    /* update VMCB for nested paging restore */
   34.63 -    if ( paging_mode_hap(v->domain) ) {
   34.64 +    if ( paging_mode_hap(v->domain) )
   34.65 +    {
   34.66          vmcb->cr0 = v->arch.hvm_svm.cpu_shadow_cr0;
   34.67 -        vmcb->cr4 = v->arch.hvm_svm.cpu_shadow_cr4 |
   34.68 -                    (HVM_CR4_HOST_MASK & ~X86_CR4_PAE);
   34.69 +        vmcb->cr4 = (v->arch.hvm_svm.cpu_shadow_cr4 |
   34.70 +                     (HVM_CR4_HOST_MASK & ~X86_CR4_PAE));
   34.71          vmcb->cr3 = c->cr3;
   34.72          vmcb->np_enable = 1;
   34.73          vmcb->g_pat = 0x0007040600070406ULL; /* guest PAT */
   34.74 @@ -514,26 +505,23 @@ int svm_vmcb_restore(struct vcpu *v, str
   34.75          gdprintk(XENLOG_INFO, "Re-injecting 0x%"PRIx32", 0x%"PRIx32"\n",
   34.76                   c->pending_event, c->error_code);
   34.77  
   34.78 -        /* VMX uses a different type for #OF and #BP; fold into "Exception"  */
   34.79 -        if ( c->pending_type == 6 ) 
   34.80 -            c->pending_type = 3;
   34.81 -        /* Sanity check */
   34.82 -        if ( c->pending_type == 1 || c->pending_type > 4 
   34.83 -             || c->pending_reserved != 0 )
   34.84 +        if ( (c->pending_type == 1) || (c->pending_type > 6) ||
   34.85 +             (c->pending_reserved != 0) )
   34.86          {
   34.87              gdprintk(XENLOG_ERR, "Invalid pending event 0x%"PRIx32"\n", 
   34.88                       c->pending_event);
   34.89              return -EINVAL;
   34.90          }
   34.91 -        /* Put this pending event in exitintinfo and svm_intr_assist()
   34.92 -         * will reinject it when we return to the guest. */
   34.93 -        vmcb->exitintinfo.bytes = c->pending_event;
   34.94 -        vmcb->exitintinfo.fields.errorcode = c->error_code;
   34.95 +
   34.96 +        if ( hvm_event_needs_reinjection(c->pending_type, c->pending_vector) )
   34.97 +        {
   34.98 +            vmcb->eventinj.bytes = c->pending_event;
   34.99 +            vmcb->eventinj.fields.errorcode = c->error_code;
  34.100 +        }
  34.101      }
  34.102  
  34.103      paging_update_paging_modes(v);
  34.104 -    /* signal paging update to ASID handler */
  34.105 -    svm_asid_g_update_paging (v);
  34.106 +    svm_asid_g_update_paging(v);
  34.107  
  34.108      return 0;
  34.109   
  34.110 @@ -965,10 +953,10 @@ static void svm_hvm_inject_exception(
  34.111      svm_inject_exception(v, trapnr, (errcode != -1), errcode);
  34.112  }
  34.113  
  34.114 -static int svm_event_injection_faulted(struct vcpu *v)
  34.115 +static int svm_event_pending(struct vcpu *v)
  34.116  {
  34.117      struct vmcb_struct *vmcb = v->arch.hvm_svm.vmcb;
  34.118 -    return vmcb->exitintinfo.fields.v;
  34.119 +    return vmcb->eventinj.fields.v;
  34.120  }
  34.121  
  34.122  static struct hvm_function_table svm_function_table = {
  34.123 @@ -1000,7 +988,7 @@ static struct hvm_function_table svm_fun
  34.124      .inject_exception     = svm_hvm_inject_exception,
  34.125      .init_ap_context      = svm_init_ap_context,
  34.126      .init_hypercall_page  = svm_init_hypercall_page,
  34.127 -    .event_injection_faulted = svm_event_injection_faulted
  34.128 +    .event_pending        = svm_event_pending
  34.129  };
  34.130  
  34.131  static void svm_npt_detect(void)
  34.132 @@ -1668,6 +1656,17 @@ static int svm_set_cr0(unsigned long val
  34.133    
  34.134      HVM_DBG_LOG(DBG_LEVEL_VMMU, "Update CR0 value = %lx", value);
  34.135  
  34.136 +    if ( (u32)value != value )
  34.137 +    {
  34.138 +        HVM_DBG_LOG(DBG_LEVEL_1,
  34.139 +                    "Guest attempts to set upper 32 bits in CR0: %lx",
  34.140 +                    value);
  34.141 +        svm_inject_exception(v, TRAP_gp_fault, 1, 0);
  34.142 +        return 0;
  34.143 +    }
  34.144 +
  34.145 +    value &= ~HVM_CR0_GUEST_RESERVED_BITS;
  34.146 +
  34.147      /* ET is reserved and should be always be 1. */
  34.148      value |= X86_CR0_ET;
  34.149  
  34.150 @@ -2420,6 +2419,7 @@ asmlinkage void svm_vmexit_handler(struc
  34.151      unsigned long eip;
  34.152      struct vcpu *v = current;
  34.153      struct vmcb_struct *vmcb = v->arch.hvm_svm.vmcb;
  34.154 +    eventinj_t eventinj;
  34.155      int inst_len, rc;
  34.156  
  34.157      exit_reason = vmcb->exitcode;
  34.158 @@ -2435,6 +2435,13 @@ asmlinkage void svm_vmexit_handler(struc
  34.159      perfc_incra(svmexits, exit_reason);
  34.160      eip = vmcb->rip;
  34.161  
  34.162 +    /* Event delivery caused this intercept? Queue for redelivery. */
  34.163 +    eventinj = vmcb->exitintinfo;
  34.164 +    if ( unlikely(eventinj.fields.v) &&
  34.165 +         hvm_event_needs_reinjection(eventinj.fields.type,
  34.166 +                                     eventinj.fields.vector) )
  34.167 +        vmcb->eventinj = eventinj;
  34.168 +
  34.169      switch ( exit_reason )
  34.170      {
  34.171      case VMEXIT_INTR:
    35.1 --- a/xen/arch/x86/hvm/vmx/intr.c	Wed Aug 01 09:40:58 2007 -0600
    35.2 +++ b/xen/arch/x86/hvm/vmx/intr.c	Wed Aug 01 16:40:30 2007 -0600
    35.3 @@ -76,10 +76,9 @@ static void enable_intr_window(struct vc
    35.4      u32 *cpu_exec_control = &v->arch.hvm_vmx.exec_control;
    35.5      u32 ctl = CPU_BASED_VIRTUAL_INTR_PENDING;
    35.6  
    35.7 -    if ( unlikely(intr_source == hvm_intack_none) )
    35.8 -        return;
    35.9 +    ASSERT(intr_source != hvm_intack_none);
   35.10  
   35.11 -    if ( unlikely(intr_source == hvm_intack_nmi) && cpu_has_vmx_vnmi )
   35.12 +    if ( (intr_source == hvm_intack_nmi) && cpu_has_vmx_vnmi )
   35.13      {
   35.14          /*
   35.15           * We set MOV-SS blocking in lieu of STI blocking when delivering an
   35.16 @@ -131,68 +130,27 @@ asmlinkage void vmx_intr_assist(void)
   35.17      int intr_vector;
   35.18      enum hvm_intack intr_source;
   35.19      struct vcpu *v = current;
   35.20 -    unsigned int idtv_info_field;
   35.21 -    unsigned long inst_len;
   35.22 +    unsigned int intr_info;
   35.23  
   35.24 +    /* Crank the handle on interrupt state. */
   35.25      pt_update_irq(v);
   35.26 -
   35.27      hvm_set_callback_irq_level();
   35.28  
   35.29 -    update_tpr_threshold(vcpu_vlapic(v));
   35.30 -
   35.31      do {
   35.32          intr_source = hvm_vcpu_has_pending_irq(v);
   35.33 -
   35.34 -        if ( unlikely(v->arch.hvm_vmx.vector_injected) )
   35.35 -        {
   35.36 -            v->arch.hvm_vmx.vector_injected = 0;
   35.37 -            enable_intr_window(v, intr_source);
   35.38 -            return;
   35.39 -        }
   35.40 -
   35.41 -        /* This could be moved earlier in the VMX resume sequence. */
   35.42 -        idtv_info_field = __vmread(IDT_VECTORING_INFO_FIELD);
   35.43 -        if ( unlikely(idtv_info_field & INTR_INFO_VALID_MASK) )
   35.44 -        {
   35.45 -            /* See SDM 3B 25.7.1.1 and .2 for info about masking resvd bits. */
   35.46 -            __vmwrite(VM_ENTRY_INTR_INFO_FIELD,
   35.47 -                      idtv_info_field & ~INTR_INFO_RESVD_BITS_MASK);
   35.48 +        if ( likely(intr_source == hvm_intack_none) )
   35.49 +            goto out;
   35.50  
   35.51 -            /*
   35.52 -             * Safe: the length will only be interpreted for software
   35.53 -             * exceptions and interrupts. If we get here then delivery of some
   35.54 -             * event caused a fault, and this always results in defined
   35.55 -             * VM_EXIT_INSTRUCTION_LEN.
   35.56 -             */
   35.57 -            inst_len = __vmread(VM_EXIT_INSTRUCTION_LEN); /* Safe */
   35.58 -            __vmwrite(VM_ENTRY_INSTRUCTION_LEN, inst_len);
   35.59 -
   35.60 -            if ( unlikely(idtv_info_field & 0x800) ) /* valid error code */
   35.61 -                __vmwrite(VM_ENTRY_EXCEPTION_ERROR_CODE,
   35.62 -                          __vmread(IDT_VECTORING_ERROR_CODE));
   35.63 -
   35.64 -            /*
   35.65 -             * Clear NMI-blocking interruptibility info if an NMI delivery
   35.66 -             * faulted. Re-delivery will re-set it (see SDM 3B 25.7.1.2).
   35.67 -             */
   35.68 -            if ( (idtv_info_field&INTR_INFO_INTR_TYPE_MASK) == INTR_TYPE_NMI )
   35.69 -                __vmwrite(GUEST_INTERRUPTIBILITY_INFO,
   35.70 -                          __vmread(GUEST_INTERRUPTIBILITY_INFO) &
   35.71 -                          ~VMX_INTR_SHADOW_NMI);
   35.72 -
   35.73 -            enable_intr_window(v, intr_source);
   35.74 -
   35.75 -            HVM_DBG_LOG(DBG_LEVEL_1, "idtv_info_field=%x", idtv_info_field);
   35.76 -            return;
   35.77 -        }
   35.78 -
   35.79 -        if ( likely(intr_source == hvm_intack_none) )
   35.80 -            return;
   35.81 -
   35.82 -        if ( !hvm_interrupts_enabled(v, intr_source) )
   35.83 +        /*
   35.84 +         * An event is already pending or the pending interrupt is masked?
   35.85 +         * Then the pending interrupt must be delayed.
   35.86 +         */
   35.87 +        intr_info = __vmread(VM_ENTRY_INTR_INFO);
   35.88 +        if ( unlikely(intr_info & INTR_INFO_VALID_MASK) ||
   35.89 +             !hvm_interrupts_enabled(v, intr_source) )
   35.90          {
   35.91              enable_intr_window(v, intr_source);
   35.92 -            return;
   35.93 +            goto out;
   35.94          }
   35.95      } while ( !hvm_vcpu_ack_pending_irq(v, intr_source, &intr_vector) );
   35.96  
   35.97 @@ -206,6 +164,14 @@ asmlinkage void vmx_intr_assist(void)
   35.98          vmx_inject_extint(v, intr_vector);
   35.99          pt_intr_post(v, intr_vector, intr_source);
  35.100      }
  35.101 +
  35.102 +    /* Is there another IRQ to queue up behind this one? */
  35.103 +    intr_source = hvm_vcpu_has_pending_irq(v);
  35.104 +    if ( unlikely(intr_source != hvm_intack_none) )
  35.105 +        enable_intr_window(v, intr_source);
  35.106 +
  35.107 + out:
  35.108 +    update_tpr_threshold(vcpu_vlapic(v));
  35.109  }
  35.110  
  35.111  /*
    36.1 --- a/xen/arch/x86/hvm/vmx/vmcs.c	Wed Aug 01 09:40:58 2007 -0600
    36.2 +++ b/xen/arch/x86/hvm/vmx/vmcs.c	Wed Aug 01 16:40:30 2007 -0600
    36.3 @@ -240,9 +240,24 @@ int vmx_cpu_up(void)
    36.4  {
    36.5      u32 eax, edx;
    36.6      int cpu = smp_processor_id();
    36.7 +    u64 cr0, vmx_cr0_fixed0, vmx_cr0_fixed1;
    36.8  
    36.9      BUG_ON(!(read_cr4() & X86_CR4_VMXE));
   36.10  
   36.11 +    /* 
   36.12 +     * Ensure the current processor operating mode meets 
   36.13 +     * the requred CRO fixed bits in VMX operation. 
   36.14 +     */
   36.15 +    cr0 = read_cr0();
   36.16 +    rdmsrl(MSR_IA32_VMX_CR0_FIXED0, vmx_cr0_fixed0);
   36.17 +    rdmsrl(MSR_IA32_VMX_CR0_FIXED1, vmx_cr0_fixed1);
   36.18 +    if ( (~cr0 & vmx_cr0_fixed0) || (cr0 & ~vmx_cr0_fixed1) )
   36.19 +    {
   36.20 +        printk("CPU%d: some settings of host CR0 are " 
   36.21 +               "not allowed in VMX operation.\n", cpu);
   36.22 +        return 0;
   36.23 +    }
   36.24 +
   36.25      rdmsr(IA32_FEATURE_CONTROL_MSR, eax, edx);
   36.26  
   36.27      if ( eax & IA32_FEATURE_CONTROL_MSR_LOCK )
   36.28 @@ -418,7 +433,7 @@ static void construct_vmcs(struct vcpu *
   36.29      __vmwrite(VM_EXIT_MSR_LOAD_COUNT, 0);
   36.30      __vmwrite(VM_ENTRY_MSR_LOAD_COUNT, 0);
   36.31  
   36.32 -    __vmwrite(VM_ENTRY_INTR_INFO_FIELD, 0);
   36.33 +    __vmwrite(VM_ENTRY_INTR_INFO, 0);
   36.34  
   36.35      __vmwrite(CR0_GUEST_HOST_MASK, ~0UL);
   36.36      __vmwrite(CR4_GUEST_HOST_MASK, ~0UL);
    37.1 --- a/xen/arch/x86/hvm/vmx/vmx.c	Wed Aug 01 09:40:58 2007 -0600
    37.2 +++ b/xen/arch/x86/hvm/vmx/vmx.c	Wed Aug 01 16:40:30 2007 -0600
    37.3 @@ -613,29 +613,14 @@ void vmx_vmcs_save(struct vcpu *v, struc
    37.4      c->sysenter_esp = __vmread(GUEST_SYSENTER_ESP);
    37.5      c->sysenter_eip = __vmread(GUEST_SYSENTER_EIP);
    37.6  
    37.7 -    /*
    37.8 -     * Save any event/interrupt that was being injected when we last
    37.9 -     * exited. IDT_VECTORING_INFO_FIELD has priority, as anything in
   37.10 -     * VM_ENTRY_INTR_INFO_FIELD is either a fault caused by the first
   37.11 -     * event, which will happen the next time, or an interrupt, which we
   37.12 -     * never inject when IDT_VECTORING_INFO_FIELD is valid.
   37.13 -     */
   37.14 -    if ( (ev = __vmread(IDT_VECTORING_INFO_FIELD)) & INTR_INFO_VALID_MASK )
   37.15 -    {
   37.16 -        c->pending_event = ev;
   37.17 -        c->error_code = __vmread(IDT_VECTORING_ERROR_CODE);
   37.18 -    }
   37.19 -    else if ( (ev = __vmread(VM_ENTRY_INTR_INFO_FIELD)) &
   37.20 -              INTR_INFO_VALID_MASK )
   37.21 +    c->pending_event = 0;
   37.22 +    c->error_code = 0;
   37.23 +    if ( ((ev = __vmread(VM_ENTRY_INTR_INFO)) & INTR_INFO_VALID_MASK) &&
   37.24 +         hvm_event_needs_reinjection((ev >> 8) & 7, ev & 0xff) )
   37.25      {
   37.26          c->pending_event = ev;
   37.27          c->error_code = __vmread(VM_ENTRY_EXCEPTION_ERROR_CODE);
   37.28      }
   37.29 -    else
   37.30 -    {
   37.31 -        c->pending_event = 0;
   37.32 -        c->error_code = 0;
   37.33 -    }
   37.34  
   37.35      vmx_vmcs_exit(v);
   37.36  }
   37.37 @@ -754,34 +739,9 @@ int vmx_vmcs_restore(struct vcpu *v, str
   37.38  
   37.39      if ( c->pending_valid )
   37.40      {
   37.41 -        vmx_vmcs_enter(v);
   37.42 -
   37.43          gdprintk(XENLOG_INFO, "Re-injecting 0x%"PRIx32", 0x%"PRIx32"\n",
   37.44                   c->pending_event, c->error_code);
   37.45  
   37.46 -        /* SVM uses type 3 ("Exception") for #OF and #BP; VMX uses type 6 */
   37.47 -        if ( (c->pending_type == 3) &&
   37.48 -             ((c->pending_vector == 3) || (c->pending_vector == 4)) )
   37.49 -            c->pending_type = 6;
   37.50 -
   37.51 -        /* For software exceptions, we need to tell the hardware the
   37.52 -         * instruction length as well (hmmm). */
   37.53 -        if ( c->pending_type > 4 )
   37.54 -        {
   37.55 -            int addrbytes, ilen;
   37.56 -            if ( (c->cs_arbytes & X86_SEG_AR_CS_LM_ACTIVE) &&
   37.57 -                 (c->msr_efer & EFER_LMA) )
   37.58 -                addrbytes = 8;
   37.59 -            else if ( c->cs_arbytes & X86_SEG_AR_DEF_OP_SIZE )
   37.60 -                addrbytes = 4;
   37.61 -            else
   37.62 -                addrbytes = 2;
   37.63 -
   37.64 -            ilen = hvm_instruction_length(c->rip, addrbytes);
   37.65 -            __vmwrite(VM_ENTRY_INSTRUCTION_LEN, ilen);
   37.66 -        }
   37.67 -
   37.68 -        /* Sanity check */
   37.69          if ( (c->pending_type == 1) || (c->pending_type > 6) ||
   37.70               (c->pending_reserved != 0) )
   37.71          {
   37.72 @@ -790,12 +750,13 @@ int vmx_vmcs_restore(struct vcpu *v, str
   37.73              return -EINVAL;
   37.74          }
   37.75  
   37.76 -        /* Re-inject the exception */
   37.77 -        __vmwrite(VM_ENTRY_INTR_INFO_FIELD, c->pending_event);
   37.78 -        __vmwrite(VM_ENTRY_EXCEPTION_ERROR_CODE, c->error_code);
   37.79 -        v->arch.hvm_vmx.vector_injected = 1;
   37.80 -
   37.81 -        vmx_vmcs_exit(v);
   37.82 +        if ( hvm_event_needs_reinjection(c->pending_type, c->pending_vector) )
   37.83 +        {
   37.84 +            vmx_vmcs_enter(v);
   37.85 +            __vmwrite(VM_ENTRY_INTR_INFO, c->pending_event);
   37.86 +            __vmwrite(VM_ENTRY_EXCEPTION_ERROR_CODE, c->error_code);
   37.87 +            vmx_vmcs_exit(v);
   37.88 +        }
   37.89      }
   37.90  
   37.91      return 0;
   37.92 @@ -1203,14 +1164,10 @@ static void vmx_update_vtpr(struct vcpu 
   37.93      /* VMX doesn't have a V_TPR field */
   37.94  }
   37.95  
   37.96 -static int vmx_event_injection_faulted(struct vcpu *v)
   37.97 +static int vmx_event_pending(struct vcpu *v)
   37.98  {
   37.99 -    unsigned int idtv_info_field;
  37.100 -
  37.101      ASSERT(v == current);
  37.102 -
  37.103 -    idtv_info_field = __vmread(IDT_VECTORING_INFO_FIELD);
  37.104 -    return (idtv_info_field & INTR_INFO_VALID_MASK);
  37.105 +    return (__vmread(VM_ENTRY_INTR_INFO) & INTR_INFO_VALID_MASK);
  37.106  }
  37.107  
  37.108  static void disable_intercept_for_msr(u32 msr)
  37.109 @@ -1261,7 +1218,7 @@ static struct hvm_function_table vmx_fun
  37.110      .inject_exception     = vmx_inject_exception,
  37.111      .init_ap_context      = vmx_init_ap_context,
  37.112      .init_hypercall_page  = vmx_init_hypercall_page,
  37.113 -    .event_injection_faulted = vmx_event_injection_faulted,
  37.114 +    .event_pending        = vmx_event_pending,
  37.115      .cpu_up               = vmx_cpu_up,
  37.116      .cpu_down             = vmx_cpu_down,
  37.117  };
  37.118 @@ -2200,6 +2157,17 @@ static int vmx_set_cr0(unsigned long val
  37.119  
  37.120      HVM_DBG_LOG(DBG_LEVEL_VMMU, "Update CR0 value = %lx", value);
  37.121  
  37.122 +    if ( (u32)value != value )
  37.123 +    {
  37.124 +        HVM_DBG_LOG(DBG_LEVEL_1,
  37.125 +                    "Guest attempts to set upper 32 bits in CR0: %lx",
  37.126 +                    value);
  37.127 +        vmx_inject_hw_exception(v, TRAP_gp_fault, 0);
  37.128 +        return 0;
  37.129 +    }
  37.130 +
  37.131 +    value &= ~HVM_CR0_GUEST_RESERVED_BITS;
  37.132 +
  37.133      /* ET is reserved and should be always be 1. */
  37.134      value |= X86_CR0_ET;
  37.135  
  37.136 @@ -2842,47 +2810,6 @@ static void vmx_do_extint(struct cpu_use
  37.137      }
  37.138  }
  37.139  
  37.140 -static void vmx_reflect_exception(struct vcpu *v)
  37.141 -{
  37.142 -    int error_code, intr_info, vector;
  37.143 -
  37.144 -    intr_info = __vmread(VM_EXIT_INTR_INFO);
  37.145 -    vector = intr_info & 0xff;
  37.146 -    if ( intr_info & INTR_INFO_DELIVER_CODE_MASK )
  37.147 -        error_code = __vmread(VM_EXIT_INTR_ERROR_CODE);
  37.148 -    else
  37.149 -        error_code = VMX_DELIVER_NO_ERROR_CODE;
  37.150 -
  37.151 -#ifndef NDEBUG
  37.152 -    {
  37.153 -        unsigned long rip;
  37.154 -
  37.155 -        rip = __vmread(GUEST_RIP);
  37.156 -        HVM_DBG_LOG(DBG_LEVEL_1, "rip = %lx, error_code = %x",
  37.157 -                    rip, error_code);
  37.158 -    }
  37.159 -#endif /* NDEBUG */
  37.160 -
  37.161 -    /*
  37.162 -     * According to Intel Virtualization Technology Specification for
  37.163 -     * the IA-32 Intel Architecture (C97063-002 April 2005), section
  37.164 -     * 2.8.3, SW_EXCEPTION should be used for #BP and #OV, and
  37.165 -     * HW_EXCEPTION used for everything else.  The main difference
  37.166 -     * appears to be that for SW_EXCEPTION, the EIP/RIP is incremented
  37.167 -     * by VM_ENTER_INSTRUCTION_LEN bytes, whereas for HW_EXCEPTION,
  37.168 -     * it is not.
  37.169 -     */
  37.170 -    if ( (intr_info & INTR_INFO_INTR_TYPE_MASK) == INTR_TYPE_SW_EXCEPTION )
  37.171 -    {
  37.172 -        int ilen = __get_instruction_length(); /* Safe: software exception */
  37.173 -        vmx_inject_sw_exception(v, vector, ilen);
  37.174 -    }
  37.175 -    else
  37.176 -    {
  37.177 -        vmx_inject_hw_exception(v, vector, error_code);
  37.178 -    }
  37.179 -}
  37.180 -
  37.181  static void vmx_failed_vmentry(unsigned int exit_reason,
  37.182                                 struct cpu_user_regs *regs)
  37.183  {
  37.184 @@ -2919,7 +2846,7 @@ static void vmx_failed_vmentry(unsigned 
  37.185  
  37.186  asmlinkage void vmx_vmexit_handler(struct cpu_user_regs *regs)
  37.187  {
  37.188 -    unsigned int exit_reason;
  37.189 +    unsigned int exit_reason, idtv_info;
  37.190      unsigned long exit_qualification, inst_len = 0;
  37.191      struct vcpu *v = current;
  37.192  
  37.193 @@ -2935,6 +2862,30 @@ asmlinkage void vmx_vmexit_handler(struc
  37.194      if ( unlikely(exit_reason & VMX_EXIT_REASONS_FAILED_VMENTRY) )
  37.195          return vmx_failed_vmentry(exit_reason, regs);
  37.196  
  37.197 +    /* Event delivery caused this intercept? Queue for redelivery. */
  37.198 +    idtv_info = __vmread(IDT_VECTORING_INFO);
  37.199 +    if ( unlikely(idtv_info & INTR_INFO_VALID_MASK) )
  37.200 +    {
  37.201 +        if ( hvm_event_needs_reinjection((idtv_info>>8)&7, idtv_info&0xff) )
  37.202 +        {
  37.203 +            /* See SDM 3B 25.7.1.1 and .2 for info about masking resvd bits. */
  37.204 +            __vmwrite(VM_ENTRY_INTR_INFO,
  37.205 +                      idtv_info & ~INTR_INFO_RESVD_BITS_MASK);
  37.206 +            if ( idtv_info & INTR_INFO_DELIVER_CODE_MASK )
  37.207 +                __vmwrite(VM_ENTRY_EXCEPTION_ERROR_CODE,
  37.208 +                          __vmread(IDT_VECTORING_ERROR_CODE));
  37.209 +        }
  37.210 +
  37.211 +        /*
  37.212 +         * Clear NMI-blocking interruptibility info if an NMI delivery faulted.
  37.213 +         * Re-delivery will re-set it (see SDM 3B 25.7.1.2).
  37.214 +         */
  37.215 +        if ( (idtv_info & INTR_INFO_INTR_TYPE_MASK) == (X86_EVENTTYPE_NMI<<8) )
  37.216 +            __vmwrite(GUEST_INTERRUPTIBILITY_INFO,
  37.217 +                      __vmread(GUEST_INTERRUPTIBILITY_INFO) &
  37.218 +                      ~VMX_INTR_SHADOW_NMI);
  37.219 +    }
  37.220 +
  37.221      switch ( exit_reason )
  37.222      {
  37.223      case EXIT_REASON_EXCEPTION_NMI:
  37.224 @@ -2957,7 +2908,7 @@ asmlinkage void vmx_vmexit_handler(struc
  37.225           * (NB. If we emulate this IRET for any reason, we should re-clear!)
  37.226           */
  37.227          if ( unlikely(intr_info & INTR_INFO_NMI_UNBLOCKED_BY_IRET) &&
  37.228 -             !(__vmread(IDT_VECTORING_INFO_FIELD) & INTR_INFO_VALID_MASK) &&
  37.229 +             !(__vmread(IDT_VECTORING_INFO) & INTR_INFO_VALID_MASK) &&
  37.230               (vector != TRAP_double_fault) )
  37.231              __vmwrite(GUEST_INTERRUPTIBILITY_INFO,
  37.232                      __vmread(GUEST_INTERRUPTIBILITY_INFO)|VMX_INTR_SHADOW_NMI);
  37.233 @@ -2995,14 +2946,12 @@ asmlinkage void vmx_vmexit_handler(struc
  37.234              vmx_inject_hw_exception(v, TRAP_page_fault, regs->error_code);
  37.235              break;
  37.236          case TRAP_nmi:
  37.237 -            if ( (intr_info & INTR_INFO_INTR_TYPE_MASK) == INTR_TYPE_NMI )
  37.238 -            {
  37.239 -                HVMTRACE_0D(NMI, v);
  37.240 -                vmx_store_cpu_guest_regs(v, regs, NULL);
  37.241 -                do_nmi(regs); /* Real NMI, vector 2: normal processing. */
  37.242 -            }
  37.243 -            else
  37.244 -                vmx_reflect_exception(v);
  37.245 +            if ( (intr_info & INTR_INFO_INTR_TYPE_MASK) !=
  37.246 +                 (X86_EVENTTYPE_NMI << 8) )
  37.247 +                goto exit_and_crash;
  37.248 +            HVMTRACE_0D(NMI, v);
  37.249 +            vmx_store_cpu_guest_regs(v, regs, NULL);
  37.250 +            do_nmi(regs); /* Real NMI, vector 2: normal processing. */
  37.251              break;
  37.252          case TRAP_machine_check:
  37.253              HVMTRACE_0D(MCE, v);
    38.1 --- a/xen/arch/x86/mm/shadow/multi.c	Wed Aug 01 09:40:58 2007 -0600
    38.2 +++ b/xen/arch/x86/mm/shadow/multi.c	Wed Aug 01 16:40:30 2007 -0600
    38.3 @@ -2905,7 +2905,7 @@ static int sh_page_fault(struct vcpu *v,
    38.4           * stack is currently considered to be a page table, so we should
    38.5           * unshadow the faulting page before exiting.
    38.6           */
    38.7 -        if ( unlikely(hvm_event_injection_faulted(v)) )
    38.8 +        if ( unlikely(hvm_event_pending(v)) )
    38.9          {
   38.10              gdprintk(XENLOG_DEBUG, "write to pagetable during event "
   38.11                       "injection: cr2=%#lx, mfn=%#lx\n", 
    39.1 --- a/xen/common/libelf/libelf-dominfo.c	Wed Aug 01 09:40:58 2007 -0600
    39.2 +++ b/xen/common/libelf/libelf-dominfo.c	Wed Aug 01 16:40:30 2007 -0600
    39.3 @@ -333,6 +333,99 @@ static int elf_xen_note_check(struct elf
    39.4      return 0;
    39.5  }
    39.6  
    39.7 +
    39.8 +static void elf_xen_loadsymtab(struct elf_binary *elf,
    39.9 +                               struct elf_dom_parms *parms)
   39.10 +{
   39.11 +    unsigned long maxva, len;
   39.12 +
   39.13 +    if ( !parms->bsd_symtab )
   39.14 +        return;
   39.15 +
   39.16 +    /* Calculate the required additional kernel space for the elf image */
   39.17 +
   39.18 +    /* The absolute base address of the elf image */
   39.19 +    maxva = elf_round_up(elf, parms->virt_kend);
   39.20 +    maxva += sizeof(long); /* Space to store the size of the elf image */
   39.21 +    /* Space for the elf and elf section headers */
   39.22 +    maxva += (elf_uval(elf, elf->ehdr, e_ehsize) +
   39.23 +              elf_shdr_count(elf) * elf_uval(elf, elf->ehdr, e_shentsize));
   39.24 +    maxva = elf_round_up(elf, maxva);
   39.25 +
   39.26 +    /* Space for the symbol and string tabs */
   39.27 +    len = (unsigned long)elf->send - (unsigned long)elf->sstart;
   39.28 +    maxva = elf_round_up(elf, maxva + len);
   39.29 +
   39.30 +    /* The address the kernel must expanded to */
   39.31 +    parms->virt_end = maxva;
   39.32 +}
   39.33 +
   39.34 +int elf_xen_dom_load_binary(struct elf_binary *elf,
   39.35 +                            struct elf_dom_parms *parms)
   39.36 +{
   39.37 +    elf_ehdr *sym_ehdr;
   39.38 +    unsigned long shdr, symtab_addr;
   39.39 +    unsigned long maxva, symbase;
   39.40 +    uint8_t i;
   39.41 +    char *p;
   39.42 +
   39.43 +    elf_load_binary(elf);
   39.44 +
   39.45 +    if ( !parms->bsd_symtab )
   39.46 +        return 0;
   39.47 +
   39.48 +#define elf_hdr_elm(_elf, _hdr, _elm, _val)     \
   39.49 +do {                                            \
   39.50 +    if ( elf_64bit(_elf) )                      \
   39.51 +        (_hdr)->e64._elm = _val;                \
   39.52 +    else                                        \
   39.53 +        (_hdr)->e32._elm = _val;                \
   39.54 +} while ( 0 )
   39.55 +
   39.56 +    /* ehdr right after the kernel image (4 byte aligned) */
   39.57 +    symbase = elf_round_up(elf, parms->virt_kend);
   39.58 +    symtab_addr = maxva = symbase + sizeof(long);
   39.59 +
   39.60 +    /* Set up Elf header. */
   39.61 +    sym_ehdr = (elf_ehdr *)symtab_addr;
   39.62 +    maxva = elf_copy_ehdr(elf, sym_ehdr);
   39.63 +
   39.64 +    elf_hdr_elm(elf, sym_ehdr, e_phoff, 0);
   39.65 +    elf_hdr_elm(elf, sym_ehdr, e_shoff, elf_uval(elf, elf->ehdr, e_ehsize));
   39.66 +    elf_hdr_elm(elf, sym_ehdr, e_phentsize, 0);
   39.67 +    elf_hdr_elm(elf, sym_ehdr, e_phnum, 0);
   39.68 +
   39.69 +    /* Copy Elf section headers. */
   39.70 +    shdr = maxva;
   39.71 +    maxva = elf_copy_shdr(elf, (elf_shdr *)shdr);
   39.72 +
   39.73 +    for ( i = 0; i < elf_shdr_count(elf); i++ )
   39.74 +    {
   39.75 +        uint8_t type;
   39.76 +        unsigned long tmp;
   39.77 +        type = elf_uval(elf, (elf_shdr *)shdr, sh_type);
   39.78 +        if ( (type == SHT_STRTAB) || (type == SHT_SYMTAB) )
   39.79 +        {
   39.80 +             elf_msg(elf, "%s: shdr %i at 0x%p -> 0x%p\n", __func__, i,
   39.81 +                     elf_section_start(elf, (elf_shdr *)shdr), (void *)maxva);
   39.82 +             tmp = elf_copy_section(elf, (elf_shdr *)shdr, (void *)maxva);
   39.83 +             /* Mangled to be based on ELF header location. */
   39.84 +             elf_hdr_elm(elf, (elf_shdr *)shdr, sh_offset,
   39.85 +                         maxva - symtab_addr);
   39.86 +             maxva = tmp;
   39.87 +        }
   39.88 +        shdr += elf_uval(elf, elf->ehdr, e_shentsize);
   39.89 +    }
   39.90 +
   39.91 +    /* Write down the actual sym size. */
   39.92 +    p = (char *)symbase;
   39.93 +    *(long *)p = maxva - symtab_addr; /* sym size */
   39.94 +
   39.95 +#undef elf_ehdr_elm
   39.96 +
   39.97 +    return 0;
   39.98 +}
   39.99 +
  39.100  static int elf_xen_addr_calc_check(struct elf_binary *elf,
  39.101                                     struct elf_dom_parms *parms)
  39.102  {
  39.103 @@ -374,22 +467,28 @@ static int elf_xen_addr_calc_check(struc
  39.104      parms->virt_offset = parms->virt_base - parms->elf_paddr_offset;
  39.105      parms->virt_kstart = elf->pstart + parms->virt_offset;
  39.106      parms->virt_kend   = elf->pend   + parms->virt_offset;
  39.107 +    parms->virt_end    = parms->virt_kend;
  39.108  
  39.109      if ( parms->virt_entry == UNSET_ADDR )
  39.110          parms->virt_entry = elf_uval(elf, elf->ehdr, e_entry);
  39.111  
  39.112 +    if ( parms->bsd_symtab )
  39.113 +        elf_xen_loadsymtab(elf, parms);
  39.114 +
  39.115      elf_msg(elf, "%s: addresses:\n", __FUNCTION__);
  39.116      elf_msg(elf, "    virt_base        = 0x%" PRIx64 "\n", parms->virt_base);
  39.117      elf_msg(elf, "    elf_paddr_offset = 0x%" PRIx64 "\n", parms->elf_paddr_offset);
  39.118      elf_msg(elf, "    virt_offset      = 0x%" PRIx64 "\n", parms->virt_offset);
  39.119      elf_msg(elf, "    virt_kstart      = 0x%" PRIx64 "\n", parms->virt_kstart);
  39.120      elf_msg(elf, "    virt_kend        = 0x%" PRIx64 "\n", parms->virt_kend);
  39.121 +    elf_msg(elf, "    virt_end         = 0x%" PRIx64 "\n", parms->virt_end);
  39.122      elf_msg(elf, "    virt_entry       = 0x%" PRIx64 "\n", parms->virt_entry);
  39.123  
  39.124      if ( (parms->virt_kstart > parms->virt_kend) ||
  39.125           (parms->virt_entry < parms->virt_kstart) ||
  39.126           (parms->virt_entry > parms->virt_kend) ||
  39.127 -         (parms->virt_base > parms->virt_kstart) )
  39.128 +         (parms->virt_base > parms->virt_kstart) ||
  39.129 +         (parms->virt_kend > parms->virt_end) )
  39.130      {
  39.131          elf_err(elf, "%s: ERROR: ELF start or entries are out of bounds.\n",
  39.132                  __FUNCTION__);
    40.1 --- a/xen/common/libelf/libelf-loader.c	Wed Aug 01 09:40:58 2007 -0600
    40.2 +++ b/xen/common/libelf/libelf-loader.c	Wed Aug 01 16:40:30 2007 -0600
    40.3 @@ -10,6 +10,8 @@ int elf_init(struct elf_binary *elf, con
    40.4  {
    40.5      const elf_shdr *shdr;
    40.6      uint64_t i, count, section, offset;
    40.7 +    uint64_t low = -1;
    40.8 +    uint64_t high = 0;
    40.9  
   40.10      if ( !elf_is_elfbinary(image) )
   40.11      {
   40.12 @@ -24,7 +26,11 @@ int elf_init(struct elf_binary *elf, con
   40.13      elf->class = elf->ehdr->e32.e_ident[EI_CLASS];
   40.14      elf->data = elf->ehdr->e32.e_ident[EI_DATA];
   40.15  
   40.16 -    /* sanity check phdr */
   40.17 +#ifdef VERBOSE
   40.18 +    elf_set_verbose(elf);
   40.19 +#endif
   40.20 +
   40.21 +    /* Sanity check phdr. */
   40.22      offset = elf_uval(elf, elf->ehdr, e_phoff) +
   40.23          elf_uval(elf, elf->ehdr, e_phentsize) * elf_phdr_count(elf);
   40.24      if ( offset > elf->size )
   40.25 @@ -34,7 +40,7 @@ int elf_init(struct elf_binary *elf, con
   40.26          return -1;
   40.27      }
   40.28  
   40.29 -    /* sanity check shdr */
   40.30 +    /* Sanity check shdr. */
   40.31      offset = elf_uval(elf, elf->ehdr, e_shoff) +
   40.32          elf_uval(elf, elf->ehdr, e_shentsize) * elf_shdr_count(elf);
   40.33      if ( offset > elf->size )
   40.34 @@ -44,29 +50,55 @@ int elf_init(struct elf_binary *elf, con
   40.35          return -1;
   40.36      }
   40.37  
   40.38 -    /* find section string table */
   40.39 +    /* Find section string table. */
   40.40      section = elf_uval(elf, elf->ehdr, e_shstrndx);
   40.41      shdr = elf_shdr_by_index(elf, section);
   40.42      if ( shdr != NULL )
   40.43          elf->sec_strtab = elf_section_start(elf, shdr);
   40.44  
   40.45 -    /* find symbol table, symbol string table */
   40.46 +    /* Find symbol table and symbol string table. */
   40.47      count = elf_shdr_count(elf);
   40.48      for ( i = 0; i < count; i++ )
   40.49      {
   40.50 +        const char *sh_symend, *sh_strend;
   40.51 +
   40.52          shdr = elf_shdr_by_index(elf, i);
   40.53          if ( elf_uval(elf, shdr, sh_type) != SHT_SYMTAB )
   40.54              continue;
   40.55          elf->sym_tab = shdr;
   40.56 +        sh_symend = (const char *)elf_section_end(elf, shdr);
   40.57          shdr = elf_shdr_by_index(elf, elf_uval(elf, shdr, sh_link));
   40.58          if ( shdr == NULL )
   40.59          {
   40.60              elf->sym_tab = NULL;
   40.61 +            sh_symend = 0;
   40.62              continue;
   40.63          }
   40.64          elf->sym_strtab = elf_section_start(elf, shdr);
   40.65 -        break;
   40.66 +        sh_strend = (const char *)elf_section_end(elf, shdr);
   40.67 +
   40.68 +        if ( low > (unsigned long)elf->sym_tab )
   40.69 +            low = (unsigned long)elf->sym_tab;
   40.70 +        if ( low > (unsigned long)shdr )
   40.71 +            low = (unsigned long)shdr;
   40.72 +
   40.73 +        if ( high < ((unsigned long)sh_symend) )
   40.74 +            high = (unsigned long)sh_symend;
   40.75 +        if ( high < ((unsigned long)sh_strend) )
   40.76 +            high = (unsigned long)sh_strend;
   40.77 +
   40.78 +        elf_msg(elf, "%s: shdr: sym_tab=%p size=0x%" PRIx64 "\n",
   40.79 +                __FUNCTION__, elf->sym_tab,
   40.80 +                elf_uval(elf, elf->sym_tab, sh_size));
   40.81 +        elf_msg(elf, "%s: shdr: str_tab=%p size=0x%" PRIx64 "\n",
   40.82 +                __FUNCTION__, elf->sym_strtab, elf_uval(elf, shdr, sh_size));
   40.83 +
   40.84 +        elf->sstart = low;
   40.85 +        elf->send = high;
   40.86 +        elf_msg(elf, "%s: symbol map: 0x%" PRIx64 " -> 0x%" PRIx64 "\n",
   40.87 +                __FUNCTION__, elf->sstart, elf->send);
   40.88      }
   40.89 +
   40.90      return 0;
   40.91  }
   40.92  
    41.1 --- a/xen/common/libelf/libelf-tools.c	Wed Aug 01 09:40:58 2007 -0600
    41.2 +++ b/xen/common/libelf/libelf-tools.c	Wed Aug 01 16:40:30 2007 -0600
    41.3 @@ -238,6 +238,36 @@ int elf_phdr_is_loadable(struct elf_bina
    41.4      return ((p_type == PT_LOAD) && (p_flags & (PF_W | PF_X)) != 0);
    41.5  }
    41.6  
    41.7 +unsigned long
    41.8 +elf_copy_ehdr(struct elf_binary *elf, void *dest)
    41.9 +{
   41.10 +    uint64_t size;
   41.11 +
   41.12 +    size = elf_uval(elf, elf->ehdr, e_ehsize);
   41.13 +    memcpy(dest, elf->ehdr, size);
   41.14 +    return elf_round_up(elf, (unsigned long)(dest) + size);
   41.15 +}
   41.16 +
   41.17 +unsigned long
   41.18 +elf_copy_shdr(struct elf_binary *elf, void *dest)
   41.19 +{
   41.20 +    uint64_t size;
   41.21 +
   41.22 +    size = elf_shdr_count(elf) * elf_uval(elf, elf->ehdr, e_shentsize);
   41.23 +    memcpy(dest, elf->image + elf_uval(elf, elf->ehdr, e_shoff), size);
   41.24 +    return elf_round_up(elf, (unsigned long)(dest) + size);
   41.25 +}
   41.26 +
   41.27 +unsigned long
   41.28 +elf_copy_section(struct elf_binary *elf, const elf_shdr *shdr, void *dest)
   41.29 +{
   41.30 +    uint64_t size;
   41.31 +
   41.32 +    size = elf_uval(elf, shdr, sh_size);
   41.33 +    memcpy(dest, elf_section_start(elf, shdr), size);
   41.34 +    return elf_round_up(elf, (unsigned long)(dest) + size);
   41.35 +}
   41.36 +
   41.37  /*
   41.38   * Local variables:
   41.39   * mode: C
    42.1 --- a/xen/drivers/acpi/tables.c	Wed Aug 01 09:40:58 2007 -0600
    42.2 +++ b/xen/drivers/acpi/tables.c	Wed Aug 01 16:40:30 2007 -0600
    42.3 @@ -73,7 +73,6 @@ struct acpi_table_sdt {
    42.4  
    42.5  static unsigned long sdt_pa;	/* Physical Address */
    42.6  static unsigned long sdt_count;	/* Table count */
    42.7 -unsigned char acpi_rsdp_rev;
    42.8  
    42.9  static struct acpi_table_sdt sdt_entry[ACPI_MAX_TABLES] __initdata;
   42.10  
   42.11 @@ -227,6 +226,17 @@ void acpi_table_print_madt_entry(acpi_ta
   42.12  	}
   42.13  }
   42.14  
   42.15 +uint8_t
   42.16 +generate_acpi_checksum(void *tbl, unsigned long len)
   42.17 +{
   42.18 +	uint8_t *ptr, sum = 0;
   42.19 +
   42.20 +	for (ptr = tbl; len > 0 ; len--, ptr++)
   42.21 +		sum += *ptr;
   42.22 +
   42.23 +	return 0 - sum;
   42.24 +}
   42.25 +
   42.26  static int
   42.27  acpi_table_compute_checksum(void *table_pointer, unsigned long length)
   42.28  {
   42.29 @@ -599,8 +609,6 @@ int __init acpi_table_init(void)
   42.30  	       "RSDP (v%3.3d %6.6s                                ) @ 0x%p\n",
   42.31  	       rsdp->revision, rsdp->oem_id, (void *)rsdp_phys);
   42.32  
   42.33 -	acpi_rsdp_rev = rsdp->revision;
   42.34 -
   42.35  	if (rsdp->revision < 2)
   42.36  		result =
   42.37  		    acpi_table_compute_checksum(rsdp,
   42.38 @@ -623,3 +631,143 @@ int __init acpi_table_init(void)
   42.39  
   42.40  	return 0;
   42.41  }
   42.42 +
   42.43 +int __init
   42.44 +acpi_table_disable(enum acpi_table_id table_id)
   42.45 +{
   42.46 +	struct acpi_table_header *header = NULL;
   42.47 +	struct acpi_table_rsdp *rsdp;
   42.48 +	unsigned long rsdp_phys;
   42.49 +	char *table_name;
   42.50 +	int id;
   42.51 +
   42.52 +	rsdp_phys = acpi_find_rsdp();
   42.53 +	if (!rsdp_phys)
   42.54 +		return -ENODEV;
   42.55 +
   42.56 +	rsdp = (struct acpi_table_rsdp *)__acpi_map_table(rsdp_phys,
   42.57 +		sizeof(struct acpi_table_rsdp));
   42.58 +	if (!rsdp)
   42.59 +		return -ENODEV;
   42.60 +
   42.61 +	for (id = 0; id < sdt_count; id++)
   42.62 +		if (sdt_entry[id].id == table_id)
   42.63 +			break;
   42.64 +
   42.65 +	if (id == sdt_count)
   42.66 +		return -ENOENT;
   42.67 +
   42.68 +	table_name = acpi_table_signatures[table_id];
   42.69 +
   42.70 +	/* First check XSDT (but only on ACPI 2.0-compatible systems) */
   42.71 +
   42.72 +	if ((rsdp->revision >= 2) &&
   42.73 +	    (((struct acpi20_table_rsdp *)rsdp)->xsdt_address)) {
   42.74 +
   42.75 +		struct acpi_table_xsdt *mapped_xsdt = NULL;
   42.76 +
   42.77 +		sdt_pa = ((struct acpi20_table_rsdp *)rsdp)->xsdt_address;
   42.78 +
   42.79 +		/* map in just the header */
   42.80 +		header = (struct acpi_table_header *)
   42.81 +		    __acpi_map_table(sdt_pa, sizeof(struct acpi_table_header));
   42.82 +
   42.83 +		if (!header) {
   42.84 +			printk(KERN_WARNING PREFIX
   42.85 +			       "Unable to map XSDT header\n");
   42.86 +			return -ENODEV;
   42.87 +		}
   42.88 +
   42.89 +		/* remap in the entire table before processing */
   42.90 +		mapped_xsdt = (struct acpi_table_xsdt *)
   42.91 +		    __acpi_map_table(sdt_pa, header->length);
   42.92 +		if (!mapped_xsdt) {
   42.93 +			printk(KERN_WARNING PREFIX "Unable to map XSDT\n");
   42.94 +			return -ENODEV;
   42.95 +		}
   42.96 +		header = &mapped_xsdt->header;
   42.97 +
   42.98 +		if (strncmp(header->signature, "XSDT", 4)) {
   42.99 +			printk(KERN_WARNING PREFIX
  42.100 +			       "XSDT signature incorrect\n");
  42.101 +			return -ENODEV;
  42.102 +		}
  42.103 +
  42.104 +		if (acpi_table_compute_checksum(header, header->length)) {
  42.105 +			printk(KERN_WARNING PREFIX "Invalid XSDT checksum\n");
  42.106 +			return -ENODEV;
  42.107 +		}
  42.108 +
  42.109 +		if (id < sdt_count) {
  42.110 +			header = (struct acpi_table_header *)
  42.111 +			   __acpi_map_table(mapped_xsdt->entry[id], sizeof(struct acpi_table_header));
  42.112 +		} else {
  42.113 +			printk(KERN_WARNING PREFIX
  42.114 +			       "Unable to disable entry %d\n",
  42.115 +			       id);
  42.116 +			return -ENODEV;
  42.117 +		}
  42.118 +	}
  42.119 +
  42.120 +	/* Then check RSDT */
  42.121 +
  42.122 +	else if (rsdp->rsdt_address) {
  42.123 +
  42.124 +		struct acpi_table_rsdt *mapped_rsdt = NULL;
  42.125 +
  42.126 +		sdt_pa = rsdp->rsdt_address;
  42.127 +
  42.128 +		/* map in just the header */
  42.129 +		header = (struct acpi_table_header *)
  42.130 +		    __acpi_map_table(sdt_pa, sizeof(struct acpi_table_header));
  42.131 +		if (!header) {
  42.132 +			printk(KERN_WARNING PREFIX
  42.133 +			       "Unable to map RSDT header\n");
  42.134 +			return -ENODEV;
  42.135 +		}
  42.136 +
  42.137 +		/* remap in the entire table before processing */
  42.138 +		mapped_rsdt = (struct acpi_table_rsdt *)
  42.139 +		    __acpi_map_table(sdt_pa, header->length);
  42.140 +		if (!mapped_rsdt) {
  42.141 +			printk(KERN_WARNING PREFIX "Unable to map RSDT\n");
  42.142 +			return -ENODEV;
  42.143 +		}
  42.144 +		header = &mapped_rsdt->header;
  42.145 +
  42.146 +		if (strncmp(header->signature, "RSDT", 4)) {
  42.147 +			printk(KERN_WARNING PREFIX
  42.148 +			       "RSDT signature incorrect\n");
  42.149 +			return -ENODEV;
  42.150 +		}
  42.151 +
  42.152 +		if (acpi_table_compute_checksum(header, header->length)) {
  42.153 +			printk(KERN_WARNING PREFIX "Invalid RSDT checksum\n");
  42.154 +			return -ENODEV;
  42.155 +		}
  42.156 +		if (id < sdt_count) {
  42.157 +			header = (struct acpi_table_header *)
  42.158 +			   __acpi_map_table(mapped_rsdt->entry[id], sizeof(struct acpi_table_header));
  42.159 +		} else {
  42.160 +			printk(KERN_WARNING PREFIX
  42.161 +			       "Unable to disable entry %d\n",
  42.162 +			       id);
  42.163 +			return -ENODEV;
  42.164 +		}
  42.165 +	}
  42.166 +
  42.167 +	else {
  42.168 +		printk(KERN_WARNING PREFIX
  42.169 +		       "No System Description Table (RSDT/XSDT) specified in RSDP\n");
  42.170 +		return -ENODEV;
  42.171 +	}
  42.172 +
  42.173 +	memcpy(header->signature, "OEMx", 4);
  42.174 +	memcpy(header->oem_id, "xxxxxx", 6);
  42.175 +	memcpy(header->oem_id+1, table_name, 4);
  42.176 +	memcpy(header->oem_table_id, "Xen     ", 8);
  42.177 +	header->checksum = 0;
  42.178 +	header->checksum = generate_acpi_checksum(header, header->length);
  42.179 +
  42.180 +	return 0;
  42.181 +}
    43.1 --- a/xen/include/asm-ia64/dom_fw_common.h	Wed Aug 01 09:40:58 2007 -0600
    43.2 +++ b/xen/include/asm-ia64/dom_fw_common.h	Wed Aug 01 16:40:30 2007 -0600
    43.3 @@ -85,7 +85,6 @@ void
    43.4  xen_ia64_efi_make_md(efi_memory_desc_t *md,
    43.5                       uint32_t type, uint64_t attr, 
    43.6                       uint64_t start, uint64_t end);
    43.7 -uint8_t generate_acpi_checksum(void *tbl, unsigned long len);
    43.8  struct fake_acpi_tables;
    43.9  void dom_fw_fake_acpi(domain_t *d, struct fake_acpi_tables *tables);
   43.10  int efi_mdt_cmp(const void *a, const void *b); 
    44.1 --- a/xen/include/asm-powerpc/grant_table.h	Wed Aug 01 09:40:58 2007 -0600
    44.2 +++ b/xen/include/asm-powerpc/grant_table.h	Wed Aug 01 16:40:30 2007 -0600
    44.3 @@ -51,6 +51,11 @@ int replace_grant_host_mapping(
    44.4  #define gnttab_shared_gmfn(d, t, i)                     \
    44.5      (mfn_to_gmfn(d, gnttab_shared_mfn(d, t, i)))
    44.6  
    44.7 +static inline void mark_dirty(struct domain *d, unsigned int mfn)
    44.8 +{
    44.9 +    return;
   44.10 +}
   44.11 +#define gnttab_mark_dirty(d, f) mark_dirty((d), (f))
   44.12  #define gnttab_log_dirty(d, f) mark_dirty((d), (f))
   44.13  
   44.14  static inline void gnttab_clear_flag(unsigned long nr, uint16_t *addr)
    45.1 --- a/xen/include/asm-powerpc/mm.h	Wed Aug 01 09:40:58 2007 -0600
    45.2 +++ b/xen/include/asm-powerpc/mm.h	Wed Aug 01 16:40:30 2007 -0600
    45.3 @@ -35,7 +35,6 @@
    45.4  #define memguard_unguard_range(_p,_l)    ((void)0)
    45.5  
    45.6  extern unsigned long xenheap_phys_end;
    45.7 -extern int boot_of_mem_avail(int pos, ulong *start, ulong *end);
    45.8  
    45.9  /*
   45.10   * Per-page-frame information.
   45.11 @@ -275,4 +274,12 @@ extern int steal_page(struct domain *d, 
   45.12  
   45.13  #define domain_get_maximum_gpfn(d) (-ENOSYS)
   45.14  
   45.15 +extern int guest_physmap_max_mem_pages(struct domain *d, unsigned long new_max);
   45.16 +
   45.17 +extern void guest_physmap_add_page(
   45.18 +    struct domain *d, unsigned long gpfn, unsigned long mfn);
   45.19 +
   45.20 +extern void guest_physmap_remove_page(
   45.21 +    struct domain *d, unsigned long gpfn, unsigned long mfn);
   45.22 +
   45.23  #endif
    46.1 --- a/xen/include/asm-powerpc/numa.h	Wed Aug 01 09:40:58 2007 -0600
    46.2 +++ b/xen/include/asm-powerpc/numa.h	Wed Aug 01 16:40:30 2007 -0600
    46.3 @@ -1,3 +1,28 @@
    46.4 +/*
    46.5 + * This program is free software; you can redistribute it and/or modify
    46.6 + * it under the terms of the GNU General Public License as published by
    46.7 + * the Free Software Foundation; either version 2 of the License, or
    46.8 + * (at your option) any later version.
    46.9 + *
   46.10 + * This program is distributed in the hope that it will be useful,
   46.11 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
   46.12 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   46.13 + * GNU General Public License for more details.
   46.14 + *
   46.15 + * You should have received a copy of the GNU General Public License
   46.16 + * along with this program; if not, write to the Free Software
   46.17 + * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
   46.18 + *
   46.19 + * Copyright (C) IBM Corp. 2007
   46.20 + *
   46.21 + * Authors: Hollis Blanchard <hollisb@us.ibm.com>
   46.22 + */
   46.23 +
   46.24 +#ifndef __ASM_NUMA_H__
   46.25 +#define __ASM_NUMA_H__
   46.26 +
   46.27  #include <xen/init.h>
   46.28  #include "../asm-x86/numa.h"
   46.29  extern void numa_initmem_init(unsigned long start_pfn, unsigned long end_pfn);
   46.30 +
   46.31 +#endif
    47.1 --- a/xen/include/asm-powerpc/shadow.h	Wed Aug 01 09:40:58 2007 -0600
    47.2 +++ b/xen/include/asm-powerpc/shadow.h	Wed Aug 01 16:40:30 2007 -0600
    47.3 @@ -32,23 +32,9 @@
    47.4        ? machine_to_phys_mapping[(mfn)]                 \
    47.5        : (mfn) )
    47.6  
    47.7 -extern int guest_physmap_max_mem_pages(struct domain *d, unsigned long new_max);
    47.8 -
    47.9 -extern void guest_physmap_add_page(
   47.10 -    struct domain *d, unsigned long gpfn, unsigned long mfn);
   47.11 -
   47.12 -extern void guest_physmap_remove_page(
   47.13 -    struct domain *d, unsigned long gpfn, unsigned long mfn);
   47.14 -
   47.15  extern void shadow_drop_references(
   47.16      struct domain *d, struct page_info *page);
   47.17  
   47.18 -static inline void mark_dirty(struct domain *d, unsigned int mfn)
   47.19 -{
   47.20 -    return;
   47.21 -}
   47.22 -#define gnttab_mark_dirty(d, f) mark_dirty((d), (f))
   47.23 -
   47.24  extern int shadow_domctl(struct domain *d, 
   47.25                     xen_domctl_shadow_op_t *sc,
   47.26                     XEN_GUEST_HANDLE(xen_domctl_t) u_domctl);
    48.1 --- a/xen/include/asm-x86/hvm/hvm.h	Wed Aug 01 09:40:58 2007 -0600
    48.2 +++ b/xen/include/asm-x86/hvm/hvm.h	Wed Aug 01 16:40:30 2007 -0600
    48.3 @@ -154,7 +154,7 @@ struct hvm_function_table {
    48.4  
    48.5      void (*init_hypercall_page)(struct domain *d, void *hypercall_page);
    48.6  
    48.7 -    int  (*event_injection_faulted)(struct vcpu *v);
    48.8 +    int  (*event_pending)(struct vcpu *v);
    48.9  
   48.10      int  (*cpu_up)(void);
   48.11      void (*cpu_down)(void);
   48.12 @@ -229,7 +229,8 @@ hvm_guest_x86_mode(struct vcpu *v)
   48.13      return hvm_funcs.guest_x86_mode(v);
   48.14  }
   48.15  
   48.16 -int hvm_instruction_length(unsigned long pc, int address_bytes);
   48.17 +int hvm_instruction_fetch(unsigned long pc, int address_bytes,
   48.18 +                          unsigned char *buf);
   48.19  
   48.20  static inline void
   48.21  hvm_update_host_cr3(struct vcpu *v)
   48.22 @@ -295,25 +296,72 @@ hvm_inject_exception(unsigned int trapnr
   48.23  
   48.24  int hvm_bringup_ap(int vcpuid, int trampoline_vector);
   48.25  
   48.26 -static inline int hvm_event_injection_faulted(struct vcpu *v)
   48.27 +static inline int hvm_event_pending(struct vcpu *v)
   48.28  {
   48.29 -    return hvm_funcs.event_injection_faulted(v);
   48.30 +    return hvm_funcs.event_pending(v);
   48.31  }
   48.32  
   48.33 +/* These reserved bits in lower 32 remain 0 after any load of CR0 */
   48.34 +#define HVM_CR0_GUEST_RESERVED_BITS             \
   48.35 +    (~((unsigned long)                          \
   48.36 +       (X86_CR0_PE | X86_CR0_MP | X86_CR0_EM |  \
   48.37 +        X86_CR0_TS | X86_CR0_ET | X86_CR0_NE |  \
   48.38 +        X86_CR0_WP | X86_CR0_AM | X86_CR0_NW |  \
   48.39 +        X86_CR0_CD | X86_CR0_PG)))
   48.40 +
   48.41  /* These bits in CR4 are owned by the host. */
   48.42  #define HVM_CR4_HOST_MASK (mmu_cr4_features & \
   48.43      (X86_CR4_VMXE | X86_CR4_PAE | X86_CR4_MCE))
   48.44  
   48.45  /* These bits in CR4 cannot be set by the guest. */
   48.46 -#define HVM_CR4_GUEST_RESERVED_BITS \
   48.47 -    ~(X86_CR4_VME | X86_CR4_PVI | X86_CR4_TSD | \
   48.48 -      X86_CR4_DE  | X86_CR4_PSE | X86_CR4_PAE | \
   48.49 -      X86_CR4_MCE | X86_CR4_PGE | X86_CR4_PCE | \
   48.50 -      X86_CR4_OSFXSR | X86_CR4_OSXMMEXCPT)
   48.51 +#define HVM_CR4_GUEST_RESERVED_BITS                     \
   48.52 +    (~((unsigned long)                                  \
   48.53 +       (X86_CR4_VME | X86_CR4_PVI | X86_CR4_TSD |       \
   48.54 +        X86_CR4_DE  | X86_CR4_PSE | X86_CR4_PAE |       \
   48.55 +        X86_CR4_MCE | X86_CR4_PGE | X86_CR4_PCE |       \
   48.56 +        X86_CR4_OSFXSR | X86_CR4_OSXMMEXCPT)))
   48.57  
   48.58  /* These exceptions must always be intercepted. */
   48.59  #define HVM_TRAP_MASK (1U << TRAP_machine_check)
   48.60  
   48.61 +/*
   48.62 + * x86 event types. This enumeration is valid for:
   48.63 + *  Intel VMX: {VM_ENTRY,VM_EXIT,IDT_VECTORING}_INTR_INFO[10:8]
   48.64 + *  AMD SVM: eventinj[10:8] and exitintinfo[10:8] (types 0-4 only)
   48.65 + */
   48.66 +#define X86_EVENTTYPE_EXT_INTR              0    /* external interrupt */
   48.67 +#define X86_EVENTTYPE_NMI                   2    /* NMI                */
   48.68 +#define X86_EVENTTYPE_HW_EXCEPTION          3    /* hardware exception */
   48.69 +#define X86_EVENTTYPE_SW_INTERRUPT          4    /* software interrupt */
   48.70 +#define X86_EVENTTYPE_SW_EXCEPTION          6    /* software exception */
   48.71 +
   48.72 +/*
   48.73 + * Need to re-inject a given event? We avoid re-injecting software exceptions
   48.74 + * and interrupts because the faulting/trapping instruction can simply be
   48.75 + * re-executed (neither VMX nor SVM update RIP when they VMEXIT during
   48.76 + * INT3/INTO/INTn).
   48.77 + */
   48.78 +static inline int hvm_event_needs_reinjection(uint8_t type, uint8_t vector)
   48.79 +{
   48.80 +    switch ( type )
   48.81 +    {
   48.82 +    case X86_EVENTTYPE_EXT_INTR:
   48.83 +    case X86_EVENTTYPE_NMI:
   48.84 +        return 1;
   48.85 +    case X86_EVENTTYPE_HW_EXCEPTION:
   48.86 +        /*
   48.87 +         * SVM uses type 3 ("HW Exception") for #OF and #BP. We explicitly
   48.88 +         * check for these vectors, as they are really SW Exceptions. SVM has
   48.89 +         * not updated RIP to point after the trapping instruction (INT3/INTO).
   48.90 +         */
   48.91 +        return (vector != 3) && (vector != 4);
   48.92 +    default:
   48.93 +        /* Software exceptions/interrupts can be re-executed (e.g., INT n). */
   48.94 +        break;
   48.95 +    }
   48.96 +    return 0;
   48.97 +}
   48.98 +
   48.99  static inline int hvm_cpu_up(void)
  48.100  {
  48.101      if ( hvm_funcs.cpu_up )
    49.1 --- a/xen/include/asm-x86/hvm/svm/vmcb.h	Wed Aug 01 09:40:58 2007 -0600
    49.2 +++ b/xen/include/asm-x86/hvm/svm/vmcb.h	Wed Aug 01 16:40:30 2007 -0600
    49.3 @@ -320,14 +320,6 @@ typedef union
    49.4      } fields;
    49.5  } __attribute__ ((packed)) eventinj_t;
    49.6  
    49.7 -enum EVENTTYPES
    49.8 -{
    49.9 -    EVENTTYPE_INTR = 0,
   49.10 -    EVENTTYPE_NMI = 2,
   49.11 -    EVENTTYPE_EXCEPTION = 3,
   49.12 -    EVENTTYPE_SWINT = 4,
   49.13 -};
   49.14 -
   49.15  typedef union 
   49.16  {
   49.17      u64 bytes;
    50.1 --- a/xen/include/asm-x86/hvm/vmx/vmcs.h	Wed Aug 01 09:40:58 2007 -0600
    50.2 +++ b/xen/include/asm-x86/hvm/vmx/vmcs.h	Wed Aug 01 16:40:30 2007 -0600
    50.3 @@ -67,9 +67,6 @@ struct arch_vmx_struct {
    50.4      /* Cache of cpu execution control. */
    50.5      u32                  exec_control;
    50.6  
    50.7 -    /* If there is vector installed in the INTR_INFO_FIELD. */
    50.8 -    u32                  vector_injected;
    50.9 -
   50.10      unsigned long        cpu_cr0; /* copy of guest CR0 */
   50.11      unsigned long        cpu_shadow_cr0; /* copy of guest read shadow CR0 */
   50.12      unsigned long        cpu_shadow_cr4; /* copy of guest read shadow CR4 */
   50.13 @@ -198,7 +195,7 @@ enum vmcs_field {
   50.14      VM_EXIT_MSR_LOAD_COUNT          = 0x00004010,
   50.15      VM_ENTRY_CONTROLS               = 0x00004012,
   50.16      VM_ENTRY_MSR_LOAD_COUNT         = 0x00004014,
   50.17 -    VM_ENTRY_INTR_INFO_FIELD        = 0x00004016,
   50.18 +    VM_ENTRY_INTR_INFO              = 0x00004016,
   50.19      VM_ENTRY_EXCEPTION_ERROR_CODE   = 0x00004018,
   50.20      VM_ENTRY_INSTRUCTION_LEN        = 0x0000401a,
   50.21      TPR_THRESHOLD                   = 0x0000401c,
   50.22 @@ -207,7 +204,7 @@ enum vmcs_field {
   50.23      VM_EXIT_REASON                  = 0x00004402,
   50.24      VM_EXIT_INTR_INFO               = 0x00004404,
   50.25      VM_EXIT_INTR_ERROR_CODE         = 0x00004406,
   50.26 -    IDT_VECTORING_INFO_FIELD        = 0x00004408,
   50.27 +    IDT_VECTORING_INFO              = 0x00004408,
   50.28      IDT_VECTORING_ERROR_CODE        = 0x0000440a,
   50.29      VM_EXIT_INSTRUCTION_LEN         = 0x0000440c,
   50.30      VMX_INSTRUCTION_INFO            = 0x0000440e,
    51.1 --- a/xen/include/asm-x86/hvm/vmx/vmx.h	Wed Aug 01 09:40:58 2007 -0600
    51.2 +++ b/xen/include/asm-x86/hvm/vmx/vmx.h	Wed Aug 01 16:40:30 2007 -0600
    51.3 @@ -94,11 +94,6 @@ void vmx_vlapic_msr_changed(struct vcpu 
    51.4  #define INTR_INFO_VALID_MASK            0x80000000      /* 31 */
    51.5  #define INTR_INFO_RESVD_BITS_MASK       0x7ffff000
    51.6  
    51.7 -#define INTR_TYPE_EXT_INTR              (0 << 8)    /* external interrupt */
    51.8 -#define INTR_TYPE_NMI                   (2 << 8)    /* NMI                */
    51.9 -#define INTR_TYPE_HW_EXCEPTION          (3 << 8)    /* hardware exception */
   51.10 -#define INTR_TYPE_SW_EXCEPTION          (6 << 8)    /* software exception */
   51.11 -
   51.12  /*
   51.13   * Exit Qualifications for MOV for Control Register Access
   51.14   */
   51.15 @@ -263,8 +258,8 @@ static inline int __vmxon (u64 addr)
   51.16      return rc;
   51.17  }
   51.18  
   51.19 -static inline void __vmx_inject_exception(struct vcpu *v, int trap, int type,
   51.20 -                                         int error_code, int ilen)
   51.21 +static inline void __vmx_inject_exception(
   51.22 +    struct vcpu *v, int trap, int type, int error_code)
   51.23  {
   51.24      unsigned long intr_fields;
   51.25  
   51.26 @@ -276,16 +271,13 @@ static inline void __vmx_inject_exceptio
   51.27       *   VM entry]", PRM Vol. 3, 22.6.1 (Interruptibility State).
   51.28       */
   51.29  
   51.30 -    intr_fields = (INTR_INFO_VALID_MASK | type | trap);
   51.31 +    intr_fields = (INTR_INFO_VALID_MASK | (type<<8) | trap);
   51.32      if ( error_code != VMX_DELIVER_NO_ERROR_CODE ) {
   51.33          __vmwrite(VM_ENTRY_EXCEPTION_ERROR_CODE, error_code);
   51.34          intr_fields |= INTR_INFO_DELIVER_CODE_MASK;
   51.35      }
   51.36  
   51.37 -    if ( ilen )
   51.38 -      __vmwrite(VM_ENTRY_INSTRUCTION_LEN, ilen);
   51.39 -
   51.40 -    __vmwrite(VM_ENTRY_INTR_INFO_FIELD, intr_fields);
   51.41 +    __vmwrite(VM_ENTRY_INTR_INFO, intr_fields);
   51.42  
   51.43      if (trap == TRAP_page_fault)
   51.44          HVMTRACE_2D(PF_INJECT, v, v->arch.hvm_vmx.cpu_cr2, error_code);
   51.45 @@ -296,29 +288,19 @@ static inline void __vmx_inject_exceptio
   51.46  static inline void vmx_inject_hw_exception(
   51.47      struct vcpu *v, int trap, int error_code)
   51.48  {
   51.49 -    v->arch.hvm_vmx.vector_injected = 1;
   51.50 -    __vmx_inject_exception(v, trap, INTR_TYPE_HW_EXCEPTION, error_code, 0);
   51.51 -}
   51.52 -
   51.53 -static inline void vmx_inject_sw_exception(
   51.54 -    struct vcpu *v, int trap, int instruction_len)
   51.55 -{
   51.56 -    v->arch.hvm_vmx.vector_injected = 1;
   51.57 -    __vmx_inject_exception(v, trap, INTR_TYPE_SW_EXCEPTION,
   51.58 -                           VMX_DELIVER_NO_ERROR_CODE,
   51.59 -                           instruction_len);
   51.60 +    __vmx_inject_exception(v, trap, X86_EVENTTYPE_HW_EXCEPTION, error_code);
   51.61  }
   51.62  
   51.63  static inline void vmx_inject_extint(struct vcpu *v, int trap)
   51.64  {
   51.65 -    __vmx_inject_exception(v, trap, INTR_TYPE_EXT_INTR,
   51.66 -                           VMX_DELIVER_NO_ERROR_CODE, 0);
   51.67 +    __vmx_inject_exception(v, trap, X86_EVENTTYPE_EXT_INTR,
   51.68 +                           VMX_DELIVER_NO_ERROR_CODE);
   51.69  }
   51.70  
   51.71  static inline void vmx_inject_nmi(struct vcpu *v)
   51.72  {
   51.73 -    __vmx_inject_exception(v, 2, INTR_TYPE_NMI,
   51.74 -                           VMX_DELIVER_NO_ERROR_CODE, 0);
   51.75 +    __vmx_inject_exception(v, 2, X86_EVENTTYPE_NMI,
   51.76 +                           VMX_DELIVER_NO_ERROR_CODE);
   51.77  }
   51.78  
   51.79  #endif /* __ASM_X86_HVM_VMX_VMX_H__ */
    52.1 --- a/xen/include/public/libelf.h	Wed Aug 01 09:40:58 2007 -0600
    52.2 +++ b/xen/include/public/libelf.h	Wed Aug 01 16:40:30 2007 -0600
    52.3 @@ -65,6 +65,8 @@ struct elf_binary {
    52.4  
    52.5      /* loaded to */
    52.6      char *dest;
    52.7 +    uint64_t sstart;
    52.8 +    uint64_t send;
    52.9      uint64_t pstart;
   52.10      uint64_t pend;
   52.11      uint64_t reloc_offset;
   52.12 @@ -91,33 +93,32 @@ struct elf_binary {
   52.13  #define elf_lsb(elf)   (ELFDATA2LSB == (elf)->data)
   52.14  #define elf_swap(elf)  (NATIVE_ELFDATA != (elf)->data)
   52.15  
   52.16 -#define elf_uval(elf, str, elem)			\
   52.17 -	((ELFCLASS64 == (elf)->class)			\
   52.18 -	? elf_access_unsigned((elf), (str),		\
   52.19 -		offsetof(typeof(*(str)),e64.elem),	\
   52.20 -		sizeof((str)->e64.elem))		\
   52.21 -	: elf_access_unsigned((elf), (str),		\
   52.22 -		offsetof(typeof(*(str)),e32.elem),	\
   52.23 -		sizeof((str)->e32.elem)))
   52.24 +#define elf_uval(elf, str, elem)                                        \
   52.25 +    ((ELFCLASS64 == (elf)->class)                                       \
   52.26 +     ? elf_access_unsigned((elf), (str),                                \
   52.27 +                           offsetof(typeof(*(str)),e64.elem),           \
   52.28 +                           sizeof((str)->e64.elem))                     \
   52.29 +     : elf_access_unsigned((elf), (str),                                \
   52.30 +                           offsetof(typeof(*(str)),e32.elem),           \
   52.31 +                           sizeof((str)->e32.elem)))
   52.32  
   52.33 -#define elf_sval(elf, str, elem)			\
   52.34 -	((ELFCLASS64 == (elf)->class)			\
   52.35 -	? elf_access_signed((elf), (str),		\
   52.36 -		offsetof(typeof(*(str)),e64.elem),	\
   52.37 -		sizeof((str)->e64.elem))		\
   52.38 -	: elf_access_signed((elf), (str),		\
   52.39 -		offsetof(typeof(*(str)),e32.elem),	\
   52.40 -		sizeof((str)->e32.elem)))
   52.41 +#define elf_sval(elf, str, elem)                                        \
   52.42 +    ((ELFCLASS64 == (elf)->class)                                       \
   52.43 +     ? elf_access_signed((elf), (str),                                  \
   52.44 +                         offsetof(typeof(*(str)),e64.elem),             \
   52.45 +                         sizeof((str)->e64.elem))                       \
   52.46 +     : elf_access_signed((elf), (str),                                  \
   52.47 +                         offsetof(typeof(*(str)),e32.elem),             \
   52.48 +                         sizeof((str)->e32.elem)))
   52.49  
   52.50 -#define elf_size(elf, str)		\
   52.51 -	((ELFCLASS64 == (elf)->class)	\
   52.52 -	? sizeof((str)->e64)		\
   52.53 -	: sizeof((str)->e32))
   52.54 +#define elf_size(elf, str)                              \
   52.55 +    ((ELFCLASS64 == (elf)->class)                       \
   52.56 +     ? sizeof((str)->e64) : sizeof((str)->e32))
   52.57  
   52.58  uint64_t elf_access_unsigned(struct elf_binary *elf, const void *ptr,
   52.59 -			     uint64_t offset, size_t size);
   52.60 +                             uint64_t offset, size_t size);
   52.61  int64_t elf_access_signed(struct elf_binary *elf, const void *ptr,
   52.62 -			  uint64_t offset, size_t size);
   52.63 +                          uint64_t offset, size_t size);
   52.64  
   52.65  uint64_t elf_round_up(struct elf_binary *elf, uint64_t addr);
   52.66  
   52.67 @@ -149,6 +150,11 @@ const elf_note *elf_note_next(struct elf
   52.68  int elf_is_elfbinary(const void *image);
   52.69  int elf_phdr_is_loadable(struct elf_binary *elf, const elf_phdr * phdr);
   52.70  
   52.71 +unsigned long elf_copy_ehdr(struct elf_binary *elf, void *dest);
   52.72 +unsigned long elf_copy_shdr(struct elf_binary *elf, void *dest);
   52.73 +unsigned long elf_copy_section(struct elf_binary *elf,
   52.74 +                               const elf_shdr *shdr, void *dest);
   52.75 +
   52.76  /* ------------------------------------------------------------------------ */
   52.77  /* xc_libelf_loader.c                                                       */
   52.78  
   52.79 @@ -185,8 +191,8 @@ struct xen_elfnote {
   52.80      enum xen_elfnote_type type;
   52.81      const char *name;
   52.82      union {
   52.83 -	const char *str;
   52.84 -	uint64_t num;
   52.85 +        const char *str;
   52.86 +        uint64_t num;
   52.87      } data;
   52.88  };
   52.89  
   52.90 @@ -215,7 +221,8 @@ struct elf_dom_parms {
   52.91      /* calculated */
   52.92      uint64_t virt_offset;
   52.93      uint64_t virt_kstart;
   52.94 -    uint64_t virt_kend;
   52.95 +    uint64_t virt_kend; /* end of kernel image */
   52.96 +    uint64_t virt_end;  /* end of kernel symtab (== virt_kend if none) */
   52.97  };
   52.98  
   52.99  static inline void elf_xen_feature_set(int nr, uint32_t * addr)
  52.100 @@ -228,14 +235,17 @@ static inline int elf_xen_feature_get(in
  52.101  }
  52.102  
  52.103  int elf_xen_parse_features(const char *features,
  52.104 -			   uint32_t *supported,
  52.105 -			   uint32_t *required);
  52.106 +                           uint32_t *supported,
  52.107 +                           uint32_t *required);
  52.108  int elf_xen_parse_note(struct elf_binary *elf,
  52.109 -		       struct elf_dom_parms *parms,
  52.110 -		       const elf_note *note);
  52.111 +                       struct elf_dom_parms *parms,
  52.112 +                       const elf_note *note);
  52.113  int elf_xen_parse_guest_info(struct elf_binary *elf,
  52.114 -			     struct elf_dom_parms *parms);
  52.115 +                             struct elf_dom_parms *parms);
  52.116  int elf_xen_parse(struct elf_binary *elf,
  52.117 -		  struct elf_dom_parms *parms);
  52.118 +                  struct elf_dom_parms *parms);
  52.119 +
  52.120 +int elf_xen_dom_load_binary(struct elf_binary *elf,
  52.121 +                            struct elf_dom_parms *parms);
  52.122  
  52.123  #endif /* __XC_LIBELF__ */
    53.1 --- a/xen/include/xen/acpi.h	Wed Aug 01 09:40:58 2007 -0600
    53.2 +++ b/xen/include/xen/acpi.h	Wed Aug 01 16:40:30 2007 -0600
    53.3 @@ -383,6 +383,7 @@ int acpi_boot_table_init (void);
    53.4  int acpi_numa_init (void);
    53.5  
    53.6  int acpi_table_init (void);
    53.7 +int acpi_table_disable(enum acpi_table_id table_id);
    53.8  int acpi_table_parse (enum acpi_table_id id, acpi_table_handler handler);
    53.9  int acpi_get_table_header_early (enum acpi_table_id id, struct acpi_table_header **header);
   53.10  int acpi_table_parse_madt (enum acpi_madt_entry_id id, acpi_madt_entry_handler handler, unsigned int max_entries);
   53.11 @@ -390,6 +391,7 @@ int acpi_table_parse_srat (enum acpi_sra
   53.12  void acpi_table_print (struct acpi_table_header *header, unsigned long phys_addr);
   53.13  void acpi_table_print_madt_entry (acpi_table_entry_header *madt);
   53.14  void acpi_table_print_srat_entry (acpi_table_entry_header *srat);
   53.15 +uint8_t generate_acpi_checksum(void *tbl, unsigned long len);
   53.16  
   53.17  /* the following four functions are architecture-dependent */
   53.18  void acpi_numa_slit_init (struct acpi_table_slit *slit);
   53.19 @@ -534,6 +536,5 @@ static inline int acpi_get_pxm(acpi_hand
   53.20  #endif
   53.21  
   53.22  extern int pnpacpi_disabled;
   53.23 -extern unsigned char acpi_rsdp_rev;
   53.24  
   53.25  #endif /*_LINUX_ACPI_H*/