WARNING - OLD ARCHIVES

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

xen-changelog

[Xen-changelog] merge with xen-unstable.hg

# HG changeset patch
# User awilliam@xxxxxxxxxxx
# Node ID acabf4bdec4fb4cca056f4c80deaab32e9f1b767
# Parent  3be4c828873766eb580541b2f977f01a72431991
# Parent  0ec4b9dfd5b441fef5422c98077b30a7f29f10d9
merge with xen-unstable.hg
---
 tools/vtpm/tpm_emulator-0.2b-x86_64.patch                        |  431 
----------
 .hgignore                                                        |    6 
 Config.mk                                                        |   14 
 Makefile                                                         |    2 
 config/ia64.mk                                                   |    4 
 config/x86_32.mk                                                 |    9 
 config/x86_64.mk                                                 |    9 
 docs/src/interface.tex                                           |   29 
 docs/src/user.tex                                                |   32 
 extras/mini-os/Makefile                                          |    3 
 extras/mini-os/include/mm.h                                      |   21 
 extras/mini-os/minios-x86_32.lds                                 |    2 
 extras/mini-os/minios-x86_64.lds                                 |    2 
 extras/mini-os/mm.c                                              |   90 +-
 extras/mini-os/x86_32.S                                          |    4 
 extras/mini-os/x86_64.S                                          |    4 
 linux-2.6-xen-sparse/arch/i386/kernel/process-xen.c              |   14 
 linux-2.6-xen-sparse/arch/i386/kernel/time-xen.c                 |   20 
 linux-2.6-xen-sparse/arch/x86_64/kernel/process-xen.c            |   15 
 linux-2.6-xen-sparse/drivers/xen/balloon/balloon.c               |    6 
 linux-2.6-xen-sparse/drivers/xen/core/cpu_hotplug.c              |    2 
 linux-2.6-xen-sparse/drivers/xen/core/smpboot.c                  |   11 
 linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/dma-mapping.h |    2 
 linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/hypercall.h   |    7 
 linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/system.h      |    4 
 linux-2.6-xen-sparse/include/asm-ia64/hypercall.h                |    7 
 linux-2.6-xen-sparse/include/asm-x86_64/mach-xen/asm/hypercall.h |    7 
 linux-2.6-xen-sparse/include/asm-x86_64/mach-xen/asm/system.h    |    4 
 linux-2.6-xen-sparse/include/xen/cpu_hotplug.h                   |    6 
 tools/Makefile                                                   |   47 -
 tools/Rules.mk                                                   |    2 
 tools/firmware/hvmloader/Makefile                                |   12 
 tools/firmware/rombios/Makefile                                  |    4 
 tools/ioemu/hw/ne2000.c                                          |   36 
 tools/libxc/Makefile                                             |   75 -
 tools/libxc/xc_core.c                                            |    2 
 tools/libxc/xc_csched.c                                          |    8 
 tools/libxc/xc_hvm_build.c                                       |    2 
 tools/libxc/xc_linux_build.c                                     |    8 
 tools/libxc/xc_load_elf.c                                        |    8 
 tools/libxc/xenctrl.h                                            |   14 
 tools/libxc/xg_private.c                                         |   15 
 tools/libxc/xg_private.h                                         |    8 
 tools/misc/Makefile                                              |    2 
 tools/python/xen/lowlevel/xc/xc.c                                |   36 
 tools/python/xen/xend/XendDomain.py                              |    8 
 tools/python/xen/xend/server/SrvDomain.py                        |    8 
 tools/python/xen/xm/main.py                                      |   18 
 tools/vtpm/Makefile                                              |   14 
 tools/vtpm/Rules.mk                                              |    1 
 tools/vtpm/tpm_emulator-0.3-x86_64.patch                         |  381 
++++++++
 tools/vtpm/vtpm.patch                                            |  407 
+++++++--
 xen/arch/x86/domain.c                                            |    2 
 xen/arch/x86/hvm/io.c                                            |   10 
 xen/arch/x86/hvm/platform.c                                      |   24 
 xen/arch/x86/hvm/svm/svm.c                                       |  160 +++
 xen/arch/x86/mm.c                                                |  175 ++--
 xen/arch/x86/shadow.c                                            |    3 
 xen/arch/x86/shadow32.c                                          |    3 
 xen/include/asm-x86/domain.h                                     |   29 
 xen/include/asm-x86/fixmap.h                                     |   10 
 xen/include/asm-x86/shadow.h                                     |   12 
 xen/include/public/sched_ctl.h                                   |    2 
 xen/include/xen/perfc.h                                          |    6 
 xen/tools/Makefile                                               |    3 
 xen/tools/figlet/Makefile                                        |    3 
 66 files changed, 1407 insertions(+), 918 deletions(-)

diff -r 3be4c8288737 -r acabf4bdec4f .hgignore
--- a/.hgignore Wed May 31 11:30:07 2006 -0600
+++ b/.hgignore Wed May 31 13:05:21 2006 -0600
@@ -113,9 +113,9 @@
 ^tools/firmware/acpi/acpigen$
 ^tools/firmware/hvmloader/hvmloader$
 ^tools/firmware/hvmloader/roms\.h$
-^tools/firmware/rombios/BIOS-bochs-latest$
-^tools/firmware/rombios/_rombios_\.c$
-^tools/firmware/rombios/rombios\.s$
+^tools/firmware/rombios/BIOS-bochs-[^/]*$
+^tools/firmware/rombios/_rombios[^/]*_\.c$
+^tools/firmware/rombios/rombios[^/]*\.s$
 ^tools/firmware/vmxassist/acpi\.h$
 ^tools/firmware/vmxassist/gen$
 ^tools/firmware/vmxassist/offsets\.h$
diff -r 3be4c8288737 -r acabf4bdec4f Config.mk
--- a/Config.mk Wed May 31 11:30:07 2006 -0600
+++ b/Config.mk Wed May 31 13:05:21 2006 -0600
@@ -39,19 +39,7 @@ CFLAGS    += -g
 CFLAGS    += -g
 endif
 
-ifeq ($(XEN_TARGET_ARCH),x86_32)
-CFLAGS  += -m32 -march=i686
-endif
-
-ifeq ($(XEN_TARGET_ARCH),x86_64)
-CFLAGS  += -m64
-endif
-
-ifeq ($(XEN_TARGET_ARCH),x86_64)
-LIBDIR = lib64
-else
-LIBDIR = lib
-endif
+include $(XEN_ROOT)/config/$(XEN_TARGET_ARCH).mk
 
 ifneq ($(EXTRA_PREFIX),)
 EXTRA_INCLUDES += $(EXTRA_PREFIX)/include
diff -r 3be4c8288737 -r acabf4bdec4f Makefile
--- a/Makefile  Wed May 31 11:30:07 2006 -0600
+++ b/Makefile  Wed May 31 13:05:21 2006 -0600
@@ -17,7 +17,7 @@ endif
 .PHONY: all
 all: dist
 
-XEN_ROOT=$(CURDIR)
+export XEN_ROOT=$(CURDIR)
 include Config.mk
 include buildconfigs/Rules.mk
 
diff -r 3be4c8288737 -r acabf4bdec4f docs/src/interface.tex
--- a/docs/src/interface.tex    Wed May 31 11:30:07 2006 -0600
+++ b/docs/src/interface.tex    Wed May 31 13:05:21 2006 -0600
@@ -205,30 +205,23 @@ implement timeout values when they block
 implement timeout values when they block.
 
 
-
-%% % akw: demoting this to a section -- not sure if there is any point
-%% % though, maybe just remove it.
-
-% KAF: Remove these random sections!
-\begin{comment}
 \section{Xen CPU Scheduling}
 
 Xen offers a uniform API for CPU schedulers.  It is possible to choose
 from a number of schedulers at boot and it should be easy to add more.
-The BVT, Atropos and Round Robin schedulers are part of the normal Xen
-distribution.  BVT provides proportional fair shares of the CPU to the
-running domains.  Atropos can be used to reserve absolute shares of
-the CPU for each domain.  Round-robin is provided as an example of
-Xen's internal scheduler API.
+The SEDF, BVT, and Credit schedulers are part of the normal Xen
+distribution.  BVT and SEDF will be going away and their use should be
+avoided once the credit scheduler has stabilized and become the default.
+The Credit scheduler provides proportional fair shares of the
+host's CPUs to the running domains. It does this while transparently
+load balancing runnable VCPUs across the whole system.
 
 \paragraph*{Note: SMP host support}
-Xen has always supported SMP host systems.  Domains are statically
-assigned to CPUs, either at creation time or when manually pinning to
-a particular CPU.  The current schedulers then run locally on each CPU
-to decide which of the assigned domains should be run there. The
-user-level control software can be used to perform coarse-grain
-load-balancing between CPUs.
-\end{comment}
+Xen has always supported SMP host systems. When using the credit scheduler,
+a domain's VCPUs will be dynamically moved across physical CPUs to maximise
+domain and system throughput. VCPUs can also be manually restricted to be
+mapped only on a subset of the host's physical CPUs, using the pinning
+mechanism.
 
 
 %% More information on the characteristics and use of these schedulers
diff -r 3be4c8288737 -r acabf4bdec4f docs/src/user.tex
--- a/docs/src/user.tex Wed May 31 11:30:07 2006 -0600
+++ b/docs/src/user.tex Wed May 31 13:05:21 2006 -0600
@@ -1093,6 +1093,36 @@ running domains in \xend's SXP configura
 
 You can get access to the console of a particular domain using 
 the \verb_# xm console_ command  (e.g.\ \verb_# xm console myVM_). 
+
+\subsection{Domain Scheduling Management Commands}
+
+The credit CPU scheduler automatically load balances guest VCPUs
+across all available physical CPUs on an SMP host. The user need
+not manually pin VCPUs to load balance the system. However, she
+can restrict which CPUs a particular VCPU may run on using
+the \path{xm vcpu-pin} command.
+
+Each guest domain is assigned a \path{weight} and a \path{cap}.
+
+A domain with a weight of 512 will get twice as much CPU as a
+domain with a weight of 256 on a contended host. Legal weights
+range from 1 to 65535 and the default is 256.
+
+The cap optionally fixes the maximum amount of CPU a guest will
+be able to consume, even if the host system has idle CPU cycles.
+The cap is expressed in percentage of one physical CPU: 100 is
+1 physical CPU, 50 is half a CPU, 400 is 4 CPUs, etc... The
+default, 0, means there is no upper cap.
+
+When you are running with the credit scheduler, you can check and
+modify your domains' weights and caps using the \path{xm sched-credit}
+command:
+
+\begin{tabular}{ll}
+\verb!xm sched-credit -d <domain>! & lists weight and cap \\
+\verb!xm sched-credit -d <domain> -w <weight>! & sets the weight \\
+\verb!xm sched-credit -d <domain> -c <cap>! & sets the cap
+\end{tabular}
 
 
 
@@ -1985,7 +2015,7 @@ editing \path{grub.conf}.
 \item [ tbuf\_size=xxx ] Set the size of the per-cpu trace buffers, in
   pages (default 0).  
 \item [ sched=xxx ] Select the CPU scheduler Xen should use.  The
-  current possibilities are `sedf' (default) and `bvt'.
+  current possibilities are `sedf' (default), `credit', and `bvt'.
 \item [ apic\_verbosity=debug,verbose ] Print more detailed
   information about local APIC and IOAPIC configuration.
 \item [ lapic ] Force use of local APIC even when left disabled by
diff -r 3be4c8288737 -r acabf4bdec4f extras/mini-os/Makefile
--- a/extras/mini-os/Makefile   Wed May 31 11:30:07 2006 -0600
+++ b/extras/mini-os/Makefile   Wed May 31 13:05:21 2006 -0600
@@ -1,7 +1,8 @@ debug ?= y
 debug ?= y
 pae ?= n
 
-include $(CURDIR)/../../Config.mk
+XEN_ROOT = ../..
+include $(XEN_ROOT)/Config.mk
 
 # Set TARGET_ARCH
 override TARGET_ARCH     := $(XEN_TARGET_ARCH)
diff -r 3be4c8288737 -r acabf4bdec4f extras/mini-os/include/mm.h
--- a/extras/mini-os/include/mm.h       Wed May 31 11:30:07 2006 -0600
+++ b/extras/mini-os/include/mm.h       Wed May 31 13:05:21 2006 -0600
@@ -53,7 +53,7 @@
 #define PADDR_BITS              32
 #define PADDR_MASK              (~0UL)
 
-#define UNMAPPED_PT_FRAMES        1
+#define NOT_L1_FRAMES           1
 #define PRIpte "08lx"
 typedef unsigned long pgentry_t;
 
@@ -71,7 +71,12 @@ typedef unsigned long pgentry_t;
 
 #define L2_MASK  ((1UL << L3_PAGETABLE_SHIFT) - 1)
 
-#define UNMAPPED_PT_FRAMES        2
+/*
+ * If starting from virtual address greater than 0xc0000000,
+ * this value will be 2 to account for final mid-level page
+ * directory which is always mapped in at this location.
+ */
+#define NOT_L1_FRAMES           3
 #define PRIpte "016llx"
 typedef uint64_t pgentry_t;
 
@@ -94,20 +99,10 @@ typedef uint64_t pgentry_t;
 #define PADDR_MASK              ((1UL << PADDR_BITS)-1)
 #define VADDR_MASK              ((1UL << VADDR_BITS)-1)
 
-/* Get physical address of page mapped by pte (paddr_t). */
-#define l1e_get_paddr(x)           \
-    ((unsigned long)(((x) & (PADDR_MASK&PAGE_MASK))))
-#define l2e_get_paddr(x)           \
-    ((unsigned long)(((x) & (PADDR_MASK&PAGE_MASK))))
-#define l3e_get_paddr(x)           \
-    ((unsigned long)(((x) & (PADDR_MASK&PAGE_MASK))))
-#define l4e_get_paddr(x)           \
-    ((unsigned long)(((x) & (PADDR_MASK&PAGE_MASK))))
-
 #define L2_MASK  ((1UL << L3_PAGETABLE_SHIFT) - 1)
 #define L3_MASK  ((1UL << L4_PAGETABLE_SHIFT) - 1)
 
-#define UNMAPPED_PT_FRAMES        3
+#define NOT_L1_FRAMES           3
 #define PRIpte "016lx"
 typedef unsigned long pgentry_t;
 
diff -r 3be4c8288737 -r acabf4bdec4f extras/mini-os/minios-x86_32.lds
--- a/extras/mini-os/minios-x86_32.lds  Wed May 31 11:30:07 2006 -0600
+++ b/extras/mini-os/minios-x86_32.lds  Wed May 31 13:05:21 2006 -0600
@@ -3,7 +3,7 @@ ENTRY(_start)
 ENTRY(_start)
 SECTIONS
 {
-  . = 0xC0000000;
+  . = 0x0;
   _text = .;                   /* Text and read-only data */
   .text : {
        *(.text)
diff -r 3be4c8288737 -r acabf4bdec4f extras/mini-os/minios-x86_64.lds
--- a/extras/mini-os/minios-x86_64.lds  Wed May 31 11:30:07 2006 -0600
+++ b/extras/mini-os/minios-x86_64.lds  Wed May 31 13:05:21 2006 -0600
@@ -3,7 +3,7 @@ ENTRY(_start)
 ENTRY(_start)
 SECTIONS
 {
-  . = 0xFFFFFFFF80000000;
+  . = 0x0;
   _text = .;                   /* Text and read-only data */
   .text : {
        *(.text)
diff -r 3be4c8288737 -r acabf4bdec4f extras/mini-os/mm.c
--- a/extras/mini-os/mm.c       Wed May 31 11:30:07 2006 -0600
+++ b/extras/mini-os/mm.c       Wed May 31 13:05:21 2006 -0600
@@ -375,7 +375,7 @@ void new_pt_frame(unsigned long *pt_pfn,
     struct mmuext_op pin_request;
     
     DEBUG("Allocating new L%d pt frame for pt_pfn=%lx, "
-           "prev_l_mfn=%lx, offset=%lx\n", 
+           "prev_l_mfn=%lx, offset=%lx", 
            level, *pt_pfn, prev_l_mfn, offset);
 
     /* We need to clear the page, otherwise we might fail to map it
@@ -442,12 +442,64 @@ void new_pt_frame(unsigned long *pt_pfn,
     mmu_updates[0].ptr = ((pgentry_t)prev_l_mfn << PAGE_SHIFT) + 
sizeof(pgentry_t) * offset;
     mmu_updates[0].val = (pgentry_t)pfn_to_mfn(*pt_pfn) << PAGE_SHIFT | prot_t;
     if(HYPERVISOR_mmu_update(mmu_updates, 1, NULL, DOMID_SELF) < 0) 
-    {            
+    {
        printk("ERROR: mmu_update failed\n");
        do_exit();
     }
 
     *pt_pfn += 1;
+}
+
+/* Checks if a pagetable frame is needed (if weren't allocated by Xen) */
+static int need_pt_frame(unsigned long virt_address, int level)
+{
+    unsigned long hyp_virt_start = HYPERVISOR_VIRT_START;
+#if defined(__x86_64__)
+    unsigned long hyp_virt_end = HYPERVISOR_VIRT_END;
+#else
+    unsigned long hyp_virt_end = 0xffffffff;
+#endif
+
+    /* In general frames will _not_ be needed if they were already
+       allocated to map the hypervisor into our VA space */
+#if defined(__x86_64__)
+    if(level == L3_FRAME)
+    {
+        if(l4_table_offset(virt_address) >= 
+           l4_table_offset(hyp_virt_start) &&
+           l4_table_offset(virt_address) <= 
+           l4_table_offset(hyp_virt_end))
+            return 0;
+        return 1;
+    } else
+#endif
+
+#if defined(__x86_64__) || defined(CONFIG_X86_PAE)
+    if(level == L2_FRAME)
+    {
+#if defined(__x86_64__)
+        if(l4_table_offset(virt_address) >= 
+           l4_table_offset(hyp_virt_start) &&
+           l4_table_offset(virt_address) <= 
+           l4_table_offset(hyp_virt_end))
+#endif
+            if(l3_table_offset(virt_address) >= 
+               l3_table_offset(hyp_virt_start) &&
+               l3_table_offset(virt_address) <= 
+               l3_table_offset(hyp_virt_end))
+                return 0;
+
+        return 1;
+    } else 
+#endif /* defined(__x86_64__) || defined(CONFIG_X86_PAE) */
+
+    /* Always need l1 frames */
+    if(level == L1_FRAME)
+        return 1;
+
+    printk("ERROR: Unknown frame level %d, hypervisor %llx,%llx\n", 
+        level, hyp_virt_start, hyp_virt_end);
+    return -1;
 }
 
 void build_pagetable(unsigned long *start_pfn, unsigned long *max_pfn)
@@ -460,11 +512,21 @@ void build_pagetable(unsigned long *star
     unsigned long offset;
     int count = 0;
 
-    pfn_to_map = (start_info.nr_pt_frames - UNMAPPED_PT_FRAMES) * 
L1_PAGETABLE_ENTRIES;
+    pfn_to_map = (start_info.nr_pt_frames - NOT_L1_FRAMES) * 
L1_PAGETABLE_ENTRIES;
+
+    if (*max_pfn >= virt_to_pfn(HYPERVISOR_VIRT_START))
+    {
+        printk("WARNING: Mini-OS trying to use Xen virtual space. "
+               "Truncating memory from %dMB to ",
+               ((unsigned long)pfn_to_virt(*max_pfn) - (unsigned 
long)&_text)>>20);
+        *max_pfn = virt_to_pfn(HYPERVISOR_VIRT_START - PAGE_SIZE);
+        printk("%dMB\n",
+               ((unsigned long)pfn_to_virt(*max_pfn) - (unsigned 
long)&_text)>>20);
+    }
 
     start_address = (unsigned long)pfn_to_virt(pfn_to_map);
     end_address = (unsigned long)pfn_to_virt(*max_pfn);
-    
+
     /* We worked out the virtual memory range to map, now mapping loop */
     printk("Mapping memory range 0x%lx - 0x%lx\n", start_address, end_address);
 
@@ -477,8 +539,9 @@ void build_pagetable(unsigned long *star
         offset = l4_table_offset(start_address);
         /* Need new L3 pt frame */
         if(!(start_address & L3_MASK)) 
-            new_pt_frame(&pt_pfn, mfn, offset, L3_FRAME);
-        
+            if(need_pt_frame(start_address, L3_FRAME)) 
+                new_pt_frame(&pt_pfn, mfn, offset, L3_FRAME);
+
         page = tab[offset];
         mfn = pte_to_mfn(page);
         tab = to_virt(mfn_to_pfn(mfn) << PAGE_SHIFT);
@@ -486,8 +549,9 @@ void build_pagetable(unsigned long *star
 #if defined(__x86_64__) || defined(CONFIG_X86_PAE)
         offset = l3_table_offset(start_address);
         /* Need new L2 pt frame */
-        if(!(start_address & L2_MASK)) 
-            new_pt_frame(&pt_pfn, mfn, offset, L2_FRAME);
+        if(!(start_address & L2_MASK))
+            if(need_pt_frame(start_address, L2_FRAME))
+                new_pt_frame(&pt_pfn, mfn, offset, L2_FRAME);
 
         page = tab[offset];
         mfn = pte_to_mfn(page);
@@ -495,16 +559,16 @@ void build_pagetable(unsigned long *star
 #endif
         offset = l2_table_offset(start_address);        
         /* Need new L1 pt frame */
-        if(!(start_address & L1_MASK)) 
-            new_pt_frame(&pt_pfn, mfn, offset, L1_FRAME);
-       
+        if(!(start_address & L1_MASK))
+            if(need_pt_frame(start_address, L1_FRAME)) 
+                new_pt_frame(&pt_pfn, mfn, offset, L1_FRAME);
+
         page = tab[offset];
         mfn = pte_to_mfn(page);
         offset = l1_table_offset(start_address);
 
         mmu_updates[count].ptr = ((pgentry_t)mfn << PAGE_SHIFT) + 
sizeof(pgentry_t) * offset;
-        mmu_updates[count].val = 
-            (pgentry_t)pfn_to_mfn(pfn_to_map++) << PAGE_SHIFT | L1_PROT;
+        mmu_updates[count].val = (pgentry_t)pfn_to_mfn(pfn_to_map++) << 
PAGE_SHIFT | L1_PROT;
         count++;
         if (count == L1_PAGETABLE_ENTRIES || pfn_to_map == *max_pfn)
         {
diff -r 3be4c8288737 -r acabf4bdec4f extras/mini-os/x86_32.S
--- a/extras/mini-os/x86_32.S   Wed May 31 11:30:07 2006 -0600
+++ b/extras/mini-os/x86_32.S   Wed May 31 13:05:21 2006 -0600
@@ -4,8 +4,8 @@
 .section __xen_guest
        .ascii  "GUEST_OS=Mini-OS"
        .ascii  ",XEN_VER=xen-3.0"
-       .ascii  ",VIRT_BASE=0xc0000000" /* &_text from minios_x86_32.lds */
-       .ascii  ",ELF_PADDR_OFFSET=0xc0000000"
+       .ascii  ",VIRT_BASE=0x0" /* &_text from minios_x86_32.lds */
+       .ascii  ",ELF_PADDR_OFFSET=0x0"
        .ascii  ",HYPERCALL_PAGE=0x2"
 #ifdef CONFIG_X86_PAE
        .ascii  ",PAE=yes"
diff -r 3be4c8288737 -r acabf4bdec4f extras/mini-os/x86_64.S
--- a/extras/mini-os/x86_64.S   Wed May 31 11:30:07 2006 -0600
+++ b/extras/mini-os/x86_64.S   Wed May 31 13:05:21 2006 -0600
@@ -4,8 +4,8 @@
 .section __xen_guest
        .ascii  "GUEST_OS=Mini-OS"
        .ascii  ",XEN_VER=xen-3.0"
-       .ascii  ",VIRT_BASE=0xffffffff80000000" /* &_text from 
minios_x86_64.lds */
-       .ascii  ",ELF_PADDR_OFFSET=0xffffffff80000000"
+       .ascii  ",VIRT_BASE=0x0" /* &_text from minios_x86_64.lds */
+       .ascii  ",ELF_PADDR_OFFSET=0x0"
        .ascii  ",HYPERCALL_PAGE=0x2"
        .ascii  ",LOADER=generic"
        .byte   0
diff -r 3be4c8288737 -r acabf4bdec4f 
linux-2.6-xen-sparse/arch/i386/kernel/process-xen.c
--- a/linux-2.6-xen-sparse/arch/i386/kernel/process-xen.c       Wed May 31 
11:30:07 2006 -0600
+++ b/linux-2.6-xen-sparse/arch/i386/kernel/process-xen.c       Wed May 31 
13:05:21 2006 -0600
@@ -55,6 +55,7 @@
 
 #include <xen/interface/physdev.h>
 #include <xen/interface/vcpu.h>
+#include <xen/cpu_hotplug.h>
 
 #include <linux/err.h>
 
@@ -101,8 +102,6 @@ EXPORT_SYMBOL(enable_hlt);
 EXPORT_SYMBOL(enable_hlt);
 
 /* XXX XEN doesn't use default_idle(), poll_idle(). Use xen_idle() instead. */
-extern void stop_hz_timer(void);
-extern void start_hz_timer(void);
 void xen_idle(void)
 {
        local_irq_disable();
@@ -112,10 +111,7 @@ void xen_idle(void)
        else {
                clear_thread_flag(TIF_POLLING_NRFLAG);
                smp_mb__after_clear_bit();
-               stop_hz_timer();
-               /* Blocking includes an implicit local_irq_enable(). */
-               HYPERVISOR_block();
-               start_hz_timer();
+               safe_halt();
                set_thread_flag(TIF_POLLING_NRFLAG);
        }
 }
@@ -132,11 +128,7 @@ static inline void play_dead(void)
        cpu_clear(smp_processor_id(), cpu_initialized);
        preempt_enable_no_resched();
        HYPERVISOR_vcpu_op(VCPUOP_down, smp_processor_id(), NULL);
-       /* Same as drivers/xen/core/smpboot.c:cpu_bringup(). */
-       cpu_init();
-       touch_softlockup_watchdog();
-       preempt_disable();
-       local_irq_enable();
+       cpu_bringup();
 }
 #else
 static inline void play_dead(void)
diff -r 3be4c8288737 -r acabf4bdec4f 
linux-2.6-xen-sparse/arch/i386/kernel/time-xen.c
--- a/linux-2.6-xen-sparse/arch/i386/kernel/time-xen.c  Wed May 31 11:30:07 
2006 -0600
+++ b/linux-2.6-xen-sparse/arch/i386/kernel/time-xen.c  Wed May 31 13:05:21 
2006 -0600
@@ -973,7 +973,7 @@ EXPORT_SYMBOL(jiffies_to_st);
  * stop_hz_timer / start_hz_timer - enter/exit 'tickless mode' on an idle cpu
  * These functions are based on implementations from arch/s390/kernel/time.c
  */
-void stop_hz_timer(void)
+static void stop_hz_timer(void)
 {
        unsigned int cpu = smp_processor_id();
        unsigned long j;
@@ -993,10 +993,26 @@ void stop_hz_timer(void)
        BUG_ON(HYPERVISOR_set_timer_op(jiffies_to_st(j)) != 0);
 }
 
-void start_hz_timer(void)
+static void start_hz_timer(void)
 {
        cpu_clear(smp_processor_id(), nohz_cpu_mask);
 }
+
+void safe_halt(void)
+{
+       stop_hz_timer();
+       /* Blocking includes an implicit local_irq_enable(). */
+       HYPERVISOR_block();
+       start_hz_timer();
+}
+EXPORT_SYMBOL(safe_halt);
+
+void halt(void)
+{
+       if (irqs_disabled())
+               HYPERVISOR_vcpu_op(VCPUOP_down, smp_processor_id(), NULL);
+}
+EXPORT_SYMBOL(halt);
 
 /* No locking required. We are only CPU running, and interrupts are off. */
 void time_resume(void)
diff -r 3be4c8288737 -r acabf4bdec4f 
linux-2.6-xen-sparse/arch/x86_64/kernel/process-xen.c
--- a/linux-2.6-xen-sparse/arch/x86_64/kernel/process-xen.c     Wed May 31 
11:30:07 2006 -0600
+++ b/linux-2.6-xen-sparse/arch/x86_64/kernel/process-xen.c     Wed May 31 
13:05:21 2006 -0600
@@ -60,6 +60,8 @@
 #include <asm/ia32.h>
 #include <asm/idle.h>
 
+#include <xen/cpu_hotplug.h>
+
 asmlinkage extern void ret_from_fork(void);
 
 unsigned long kernel_thread_flags = CLONE_VM | CLONE_UNTRACED;
@@ -118,8 +120,6 @@ void exit_idle(void)
 }
 
 /* XXX XEN doesn't use default_idle(), poll_idle(). Use xen_idle() instead. */
-extern void stop_hz_timer(void);
-extern void start_hz_timer(void);
 void xen_idle(void)
 {
        local_irq_disable();
@@ -129,10 +129,7 @@ void xen_idle(void)
        else {
                clear_thread_flag(TIF_POLLING_NRFLAG);
                smp_mb__after_clear_bit();
-               stop_hz_timer();
-               /* Blocking includes an implicit local_irq_enable(). */
-               HYPERVISOR_block();
-               start_hz_timer();
+               safe_halt();
                set_thread_flag(TIF_POLLING_NRFLAG);
        }
 }
@@ -145,11 +142,7 @@ static inline void play_dead(void)
        cpu_clear(smp_processor_id(), cpu_initialized);
        preempt_enable_no_resched();
        HYPERVISOR_vcpu_op(VCPUOP_down, smp_processor_id(), NULL);
-       /* Same as drivers/xen/core/smpboot.c:cpu_bringup(). */
-       cpu_init();
-       touch_softlockup_watchdog();
-       preempt_disable();
-       local_irq_enable();
+       cpu_bringup();
 }
 #else
 static inline void play_dead(void)
diff -r 3be4c8288737 -r acabf4bdec4f 
linux-2.6-xen-sparse/drivers/xen/balloon/balloon.c
--- a/linux-2.6-xen-sparse/drivers/xen/balloon/balloon.c        Wed May 31 
11:30:07 2006 -0600
+++ b/linux-2.6-xen-sparse/drivers/xen/balloon/balloon.c        Wed May 31 
13:05:21 2006 -0600
@@ -360,12 +360,6 @@ static void balloon_process(void *unused
 /* Resets the Xen limit, sets new target, and kicks off processing. */
 static void set_new_target(unsigned long target)
 {
-       unsigned long min_target;
-
-       /* Do not allow target to reduce below 2% of maximum memory size. */
-       min_target = max_pfn / 50;
-       target = max(target, min_target);
-
        /* No need for lock. Not read-modify-write updates. */
        hard_limit   = ~0UL;
        target_pages = target;
diff -r 3be4c8288737 -r acabf4bdec4f 
linux-2.6-xen-sparse/drivers/xen/core/cpu_hotplug.c
--- a/linux-2.6-xen-sparse/drivers/xen/core/cpu_hotplug.c       Wed May 31 
11:30:07 2006 -0600
+++ b/linux-2.6-xen-sparse/drivers/xen/core/cpu_hotplug.c       Wed May 31 
13:05:21 2006 -0600
@@ -160,7 +160,7 @@ void smp_resume(void)
                vcpu_hotplug(cpu);
 }
 
-int cpu_up_is_allowed(unsigned int cpu)
+int cpu_up_check(unsigned int cpu)
 {
        int rc = 0;
 
diff -r 3be4c8288737 -r acabf4bdec4f 
linux-2.6-xen-sparse/drivers/xen/core/smpboot.c
--- a/linux-2.6-xen-sparse/drivers/xen/core/smpboot.c   Wed May 31 11:30:07 
2006 -0600
+++ b/linux-2.6-xen-sparse/drivers/xen/core/smpboot.c   Wed May 31 13:05:21 
2006 -0600
@@ -150,12 +150,17 @@ static void xen_smp_intr_exit(unsigned i
 }
 #endif
 
-static void cpu_bringup(void)
+void cpu_bringup(void)
 {
        cpu_init();
        touch_softlockup_watchdog();
        preempt_disable();
        local_irq_enable();
+}
+
+static void cpu_bringup_and_idle(void)
+{
+       cpu_bringup();
        cpu_idle();
 }
 
@@ -180,7 +185,7 @@ void cpu_initialize_context(unsigned int
        ctxt.user_regs.fs = 0;
        ctxt.user_regs.gs = 0;
        ctxt.user_regs.ss = __KERNEL_DS;
-       ctxt.user_regs.eip = (unsigned long)cpu_bringup;
+       ctxt.user_regs.eip = (unsigned long)cpu_bringup_and_idle;
        ctxt.user_regs.eflags = X86_EFLAGS_IF | 0x1000; /* IOPL_RING1 */
 
        memset(&ctxt.fpu_ctxt, 0, sizeof(ctxt.fpu_ctxt));
@@ -400,7 +405,7 @@ int __devinit __cpu_up(unsigned int cpu)
 {
        int rc;
 
-       rc = cpu_up_is_allowed(cpu);
+       rc = cpu_up_check(cpu);
        if (rc)
                return rc;
 
diff -r 3be4c8288737 -r acabf4bdec4f 
linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/dma-mapping.h
--- a/linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/dma-mapping.h  Wed May 
31 11:30:07 2006 -0600
+++ b/linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/dma-mapping.h  Wed May 
31 13:05:21 2006 -0600
@@ -128,8 +128,6 @@ dma_get_cache_alignment(void)
         * maximum possible, to be safe */
        return (1 << INTERNODE_CACHE_SHIFT);
 }
-#else
-extern int dma_get_cache_alignment(void);
 #endif
 
 #define dma_is_consistent(d)   (1)
diff -r 3be4c8288737 -r acabf4bdec4f 
linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/hypercall.h
--- a/linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/hypercall.h    Wed May 
31 11:30:07 2006 -0600
+++ b/linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/hypercall.h    Wed May 
31 13:05:21 2006 -0600
@@ -260,6 +260,13 @@ HYPERVISOR_event_channel_op(
 }
 
 static inline int
+HYPERVISOR_acm_op(
+       int cmd, void *arg)
+{
+       return _hypercall2(int, acm_op, cmd, arg);
+}
+
+static inline int
 HYPERVISOR_xen_version(
        int cmd, void *arg)
 {
diff -r 3be4c8288737 -r acabf4bdec4f 
linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/system.h
--- a/linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/system.h       Wed May 
31 11:30:07 2006 -0600
+++ b/linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/system.h       Wed May 
31 13:05:21 2006 -0600
@@ -625,8 +625,8 @@ do {                                                        
                \
                preempt_enable_no_resched();                            \
 } while (0)
 
-#define safe_halt()            ((void)0)
-#define halt()                 ((void)0)
+void safe_halt(void);
+void halt(void);
 
 #define __save_and_cli(x)                                              \
 do {                                                                   \
diff -r 3be4c8288737 -r acabf4bdec4f 
linux-2.6-xen-sparse/include/asm-ia64/hypercall.h
--- a/linux-2.6-xen-sparse/include/asm-ia64/hypercall.h Wed May 31 11:30:07 
2006 -0600
+++ b/linux-2.6-xen-sparse/include/asm-ia64/hypercall.h Wed May 31 13:05:21 
2006 -0600
@@ -247,6 +247,13 @@ HYPERVISOR_event_channel_op(
 }
 
 static inline int
+HYPERVISOR_acm_op(
+       unsigned int cmd, void *arg)
+{
+    return _hypercall2(int, acm_op, cmd, arg);
+}
+
+static inline int
 HYPERVISOR_xen_version(
     int cmd, void *arg)
 {
diff -r 3be4c8288737 -r acabf4bdec4f 
linux-2.6-xen-sparse/include/asm-x86_64/mach-xen/asm/hypercall.h
--- a/linux-2.6-xen-sparse/include/asm-x86_64/mach-xen/asm/hypercall.h  Wed May 
31 11:30:07 2006 -0600
+++ b/linux-2.6-xen-sparse/include/asm-x86_64/mach-xen/asm/hypercall.h  Wed May 
31 13:05:21 2006 -0600
@@ -258,6 +258,13 @@ HYPERVISOR_event_channel_op(
 }
 
 static inline int
+HYPERVISOR_acm_op(
+       int cmd, void *arg)
+{
+       return _hypercall2(int, acm_op, cmd, arg);
+}
+
+static inline int
 HYPERVISOR_xen_version(
        int cmd, void *arg)
 {
diff -r 3be4c8288737 -r acabf4bdec4f 
linux-2.6-xen-sparse/include/asm-x86_64/mach-xen/asm/system.h
--- a/linux-2.6-xen-sparse/include/asm-x86_64/mach-xen/asm/system.h     Wed May 
31 11:30:07 2006 -0600
+++ b/linux-2.6-xen-sparse/include/asm-x86_64/mach-xen/asm/system.h     Wed May 
31 13:05:21 2006 -0600
@@ -424,8 +424,8 @@ do {                                                        
                \
        preempt_enable_no_resched();                                    \
        ___x; })
 
-#define safe_halt()            ((void)0)
-#define halt()                 ((void)0)
+void safe_halt(void);
+void halt(void);
 
 void cpu_idle_wait(void);
 
diff -r 3be4c8288737 -r acabf4bdec4f 
linux-2.6-xen-sparse/include/xen/cpu_hotplug.h
--- a/linux-2.6-xen-sparse/include/xen/cpu_hotplug.h    Wed May 31 11:30:07 
2006 -0600
+++ b/linux-2.6-xen-sparse/include/xen/cpu_hotplug.h    Wed May 31 13:05:21 
2006 -0600
@@ -13,14 +13,16 @@ void cpu_initialize_context(unsigned int
 #define cpu_initialize_context(cpu)    ((void)0)
 #endif
 
-int cpu_up_is_allowed(unsigned int cpu);
+int cpu_up_check(unsigned int cpu);
 void init_xenbus_allowed_cpumask(void);
 int smp_suspend(void);
 void smp_resume(void);
 
+void cpu_bringup(void);
+
 #else /* !defined(CONFIG_HOTPLUG_CPU) */
 
-#define cpu_up_is_allowed(cpu)         (1)
+#define cpu_up_check(cpu)              (0)
 #define init_xenbus_allowed_cpumask()  ((void)0)
 
 static inline int smp_suspend(void)
diff -r 3be4c8288737 -r acabf4bdec4f tools/Makefile
--- a/tools/Makefile    Wed May 31 11:30:07 2006 -0600
+++ b/tools/Makefile    Wed May 31 13:05:21 2006 -0600
@@ -1,39 +1,38 @@ XEN_ROOT = ../
 XEN_ROOT = ../
 include $(XEN_ROOT)/tools/Rules.mk
 
-SUBDIRS :=
-SUBDIRS += libxc
-SUBDIRS += xenstore
-SUBDIRS += misc
-SUBDIRS += examples
-SUBDIRS += xentrace
-SUBDIRS += xcutils
-SUBDIRS += firmware
-SUBDIRS += security
-SUBDIRS += console
-SUBDIRS += xenmon
-SUBDIRS += guest-headers
-ifeq ($(VTPM_TOOLS),y)
-SUBDIRS += vtpm_manager
-SUBDIRS += vtpm
-endif
-SUBDIRS += xenstat
+SUBDIRS-y :=
+SUBDIRS-y += libxc
+SUBDIRS-y += xenstore
+SUBDIRS-y += misc
+SUBDIRS-y += examples
+SUBDIRS-y += xentrace
+SUBDIRS-$(CONFIG_X86) += xcutils
+SUBDIRS-y += firmware
+SUBDIRS-y += security
+SUBDIRS-y += console
+SUBDIRS-y += xenmon
+SUBDIRS-y += guest-headers
+SUBDIRS-$(VTPM_TOOLS) += vtpm_manager
+SUBDIRS-$(VTPM_TOOLS) += vtpm
+SUBDIRS-y += xenstat
+
 # These don't cross-compile
 ifeq ($(XEN_COMPILE_ARCH),$(XEN_TARGET_ARCH))
-SUBDIRS += python
-SUBDIRS += pygrub
+SUBDIRS-y += python
+SUBDIRS-y += pygrub
 endif
 
 .PHONY: all
 all: check
-       @set -e; for subdir in $(SUBDIRS); do \
+       @set -e; for subdir in $(SUBDIRS-y); do \
                $(MAKE) -C $$subdir $@; \
        done
        $(MAKE) ioemu
 
 .PHONY: install
 install: check
-       @set -e; for subdir in $(SUBDIRS); do \
+       @set -e; for subdir in $(SUBDIRS-y); do \
                $(MAKE) -C $$subdir $@; \
        done
        $(MAKE) ioemuinstall
@@ -41,7 +40,7 @@ install: check
 
 .PHONY: clean
 clean: check_clean
-       @set -e; for subdir in $(SUBDIRS); do \
+       @set -e; for subdir in $(SUBDIRS-y); do \
                $(MAKE) -C $$subdir $@; \
        done
        $(MAKE) ioemuclean
@@ -55,10 +54,10 @@ check_clean:
        $(MAKE) -C check clean
 
 .PHONY: ioemu ioemuinstall ioemuclean
-ifndef XEN_NO_IOEMU
+ifdef CONFIG_IOEMU
 ioemu ioemuinstall ioemuclean:
        [ -f ioemu/config-host.h ] || \
-       (cd ioemu; ./configure --prefix=usr)
+       (cd ioemu; sh ./configure --prefix=usr)
        $(MAKE) -C ioemu $(patsubst ioemu%,%,$@)
 else
 ioemu ioemuinstall ioemuclean:
diff -r 3be4c8288737 -r acabf4bdec4f tools/Rules.mk
--- a/tools/Rules.mk    Wed May 31 11:30:07 2006 -0600
+++ b/tools/Rules.mk    Wed May 31 13:05:21 2006 -0600
@@ -4,6 +4,8 @@ all:
 all:
 
 include $(XEN_ROOT)/Config.mk
+
+CONFIG_$(shell uname -s) := y
 
 XEN_XC             = $(XEN_ROOT)/tools/python/xen/lowlevel/xc
 XEN_LIBXC          = $(XEN_ROOT)/tools/libxc
diff -r 3be4c8288737 -r acabf4bdec4f tools/firmware/hvmloader/Makefile
--- a/tools/firmware/hvmloader/Makefile Wed May 31 11:30:07 2006 -0600
+++ b/tools/firmware/hvmloader/Makefile Wed May 31 13:05:21 2006 -0600
@@ -51,12 +51,12 @@ hvmloader: roms.h hvmloader.c acpi_madt.
        $(OBJCOPY) hvmloader.tmp hvmloader
        rm -f hvmloader.tmp
 
-roms.h:        ../rombios/BIOS-bochs-latest ../vgabios/VGABIOS-lgpl-latest.bin 
../vgabios/VGABIOS-lgpl-latest.cirrus.bin ../vmxassist/vmxassist.bin
-       ./mkhex rombios ../rombios/BIOS-bochs-latest > roms.h
-       ./mkhex vgabios_stdvga ../vgabios/VGABIOS-lgpl-latest.bin >> roms.h
-       ./mkhex vgabios_cirrusvga ../vgabios/VGABIOS-lgpl-latest.cirrus.bin >> 
roms.h
-       ./mkhex vmxassist ../vmxassist/vmxassist.bin >> roms.h
-       ./mkhex acpi ../acpi/acpi.bin >> roms.h
+roms.h:        ../rombios/BIOS-bochs-8-processors 
../vgabios/VGABIOS-lgpl-latest.bin ../vgabios/VGABIOS-lgpl-latest.cirrus.bin 
../vmxassist/vmxassist.bin
+       sh ./mkhex rombios ../rombios/BIOS-bochs-8-processors > roms.h
+       sh ./mkhex vgabios_stdvga ../vgabios/VGABIOS-lgpl-latest.bin >> roms.h
+       sh ./mkhex vgabios_cirrusvga ../vgabios/VGABIOS-lgpl-latest.cirrus.bin 
>> roms.h
+       sh ./mkhex vmxassist ../vmxassist/vmxassist.bin >> roms.h
+       sh ./mkhex acpi ../acpi/acpi.bin >> roms.h
 
 .PHONY: clean
 clean:
diff -r 3be4c8288737 -r acabf4bdec4f tools/firmware/rombios/Makefile
--- a/tools/firmware/rombios/Makefile   Wed May 31 11:30:07 2006 -0600
+++ b/tools/firmware/rombios/Makefile   Wed May 31 13:05:21 2006 -0600
@@ -1,7 +1,7 @@ BIOS_BUILDS = BIOS-bochs-latest
-BIOS_BUILDS = BIOS-bochs-latest
+#BIOS_BUILDS = BIOS-bochs-latest
 #BIOS_BUILDS += BIOS-bochs-2-processors
 #BIOS_BUILDS += BIOS-bochs-4-processors
-#BIOS_BUILDS += BIOS-bochs-8-processors
+BIOS_BUILDS += BIOS-bochs-8-processors
 
 .PHONY: all
 all: bios
diff -r 3be4c8288737 -r acabf4bdec4f tools/ioemu/hw/ne2000.c
--- a/tools/ioemu/hw/ne2000.c   Wed May 31 11:30:07 2006 -0600
+++ b/tools/ioemu/hw/ne2000.c   Wed May 31 13:05:21 2006 -0600
@@ -147,9 +147,33 @@ static void ne2000_reset(NE2000State *s)
     }
 }
 
+static int ne2000_buffer_full(NE2000State *s)
+{
+    int avail, index, boundary;
+
+    index = s->curpag << 8;
+    boundary = s->boundary << 8;
+    if (index <= boundary)
+        /* when index == boundary, we should assume the
+         * buffer is full instead of empty!
+         */
+        avail = boundary - index;
+    else
+        avail = (s->stop - s->start) - (index - boundary);
+
+    return (avail < (MAX_ETH_FRAME_SIZE + 4));
+}
+
 static void ne2000_update_irq(NE2000State *s)
 {
     int isr;
+
+    if (ne2000_buffer_full(s)) {
+        /* The freeing space is not enough, tell the ne2k driver
+         * to fetch these packets!
+         */
+        s->isr |= ENISR_RX;
+    }
     isr = s->isr & s->imr;
 #if defined(DEBUG_NE2000)
     printf("NE2000: Set IRQ line %d to %d (%02x %02x)\n",
@@ -168,19 +192,11 @@ static int ne2000_can_receive(void *opaq
 static int ne2000_can_receive(void *opaque)
 {
     NE2000State *s = opaque;
-    int avail, index, boundary;
     
     if (s->cmd & E8390_STOP)
         return 0;
-    index = s->curpag << 8;
-    boundary = s->boundary << 8;
-    if (index < boundary)
-        avail = boundary - index;
-    else
-        avail = (s->stop - s->start) - (index - boundary);
-    if (avail < (MAX_ETH_FRAME_SIZE + 4))
-        return 0;
-    return MAX_ETH_FRAME_SIZE;
+
+    return (ne2000_buffer_full(s) ? 0 : MAX_ETH_FRAME_SIZE);
 }
 
 #define MIN_BUF_SIZE 60
diff -r 3be4c8288737 -r acabf4bdec4f tools/libxc/Makefile
--- a/tools/libxc/Makefile      Wed May 31 11:30:07 2006 -0600
+++ b/tools/libxc/Makefile      Wed May 31 13:05:21 2006 -0600
@@ -10,43 +10,30 @@ XEN_ROOT = ../..
 XEN_ROOT = ../..
 include $(XEN_ROOT)/tools/Rules.mk
 
-SRCS       :=
-SRCS       += xc_bvtsched.c
-SRCS       += xc_core.c
-SRCS       += xc_domain.c
-SRCS       += xc_evtchn.c
-SRCS       += xc_misc.c
-SRCS       += xc_acm.c   
-SRCS       += xc_physdev.c
-SRCS       += xc_private.c
-SRCS       += xc_sedf.c
-SRCS       += xc_csched.c
-SRCS       += xc_tbuf.c
+CTRL_SRCS-y       :=
+CTRL_SRCS-y       += xc_bvtsched.c
+CTRL_SRCS-y       += xc_core.c
+CTRL_SRCS-y       += xc_domain.c
+CTRL_SRCS-y       += xc_evtchn.c
+CTRL_SRCS-y       += xc_misc.c
+CTRL_SRCS-y       += xc_acm.c   
+CTRL_SRCS-y       += xc_physdev.c
+CTRL_SRCS-y       += xc_private.c
+CTRL_SRCS-y       += xc_sedf.c
+CTRL_SRCS-y       += xc_csched.c
+CTRL_SRCS-y       += xc_tbuf.c
+CTRL_SRCS-$(CONFIG_X86) += xc_ptrace.c xc_ptrace_core.c xc_pagetab.c
+CTRL_SRCS-$(CONFIG_Linux) += xc_linux.c
 
-ifeq ($(patsubst x86%,x86,$(XEN_TARGET_ARCH)),x86)
-SRCS       += xc_ptrace.c
-SRCS       += xc_ptrace_core.c
-SRCS       += xc_pagetab.c
-endif
-
-SRCS_Linux += xc_linux.c
-
-SRCS       += $(SRCS_Linux)
-
-BUILD_SRCS :=
-BUILD_SRCS += xc_linux_build.c
-BUILD_SRCS += xc_load_bin.c
-BUILD_SRCS += xc_load_elf.c
-BUILD_SRCS += xg_private.c
-
-ifeq ($(XEN_TARGET_ARCH),ia64)
-BUILD_SRCS += xc_ia64_stubs.c
-else
-BUILD_SRCS += xc_load_aout9.c
-BUILD_SRCS += xc_linux_restore.c
-BUILD_SRCS += xc_linux_save.c
-BUILD_SRCS += xc_hvm_build.c
-endif
+GUEST_SRCS-y :=
+GUEST_SRCS-y += xc_linux_build.c
+GUEST_SRCS-y += xc_load_bin.c
+GUEST_SRCS-y += xc_load_elf.c
+GUEST_SRCS-y += xg_private.c
+GUEST_SRCS-$(CONFIG_IA64) += xc_ia64_stubs.c
+GUEST_SRCS-$(CONFIG_PLAN9) += xc_load_aout9.c
+GUEST_SRCS-$(CONFIG_MIGRATE) += xc_linux_restore.c xc_linux_save.c
+GUEST_SRCS-$(CONFIG_HVM) += xc_hvm_build.c
 
 CFLAGS   += -Werror
 CFLAGS   += -fno-strict-aliasing
@@ -61,11 +48,11 @@ LDFLAGS  += -L.
 LDFLAGS  += -L.
 DEPS     = .*.d
 
-LIB_OBJS := $(patsubst %.c,%.o,$(SRCS))
-PIC_OBJS := $(patsubst %.c,%.opic,$(SRCS))
+CTRL_LIB_OBJS := $(patsubst %.c,%.o,$(CTRL_SRCS-y))
+CTRL_PIC_OBJS := $(patsubst %.c,%.opic,$(CTRL_SRCS-y))
 
-LIB_BUILD_OBJS := $(patsubst %.c,%.o,$(BUILD_SRCS))
-PIC_BUILD_OBJS := $(patsubst %.c,%.opic,$(BUILD_SRCS))
+GUEST_LIB_OBJS := $(patsubst %.c,%.o,$(GUEST_SRCS-y))
+GUEST_PIC_OBJS := $(patsubst %.c,%.opic,$(GUEST_SRCS-y))
 
 LIB := libxenctrl.a
 LIB += libxenctrl.so libxenctrl.so.$(MAJOR) libxenctrl.so.$(MAJOR).$(MINOR)
@@ -125,7 +112,7 @@ rpm: build
 
 # libxenctrl
 
-libxenctrl.a: $(LIB_OBJS)
+libxenctrl.a: $(CTRL_LIB_OBJS)
        $(AR) rc $@ $^
 
 libxenctrl.so: libxenctrl.so.$(MAJOR)
@@ -133,12 +120,12 @@ libxenctrl.so.$(MAJOR): libxenctrl.so.$(
 libxenctrl.so.$(MAJOR): libxenctrl.so.$(MAJOR).$(MINOR)
        ln -sf $< $@
 
-libxenctrl.so.$(MAJOR).$(MINOR): $(PIC_OBJS)
+libxenctrl.so.$(MAJOR).$(MINOR): $(CTRL_PIC_OBJS)
        $(CC) $(CFLAGS) $(LDFLAGS) -Wl,-soname -Wl,libxenctrl.so.$(MAJOR) 
-shared -o $@ $^
 
 # libxenguest
 
-libxenguest.a: $(LIB_BUILD_OBJS)
+libxenguest.a: $(GUEST_LIB_OBJS)
        $(AR) rc $@ $^
 
 libxenguest.so: libxenguest.so.$(MAJOR)
@@ -146,7 +133,7 @@ libxenguest.so.$(MAJOR): libxenguest.so.
 libxenguest.so.$(MAJOR): libxenguest.so.$(MAJOR).$(MINOR)
        ln -sf $< $@
 
-libxenguest.so.$(MAJOR).$(MINOR): $(PIC_BUILD_OBJS) libxenctrl.so
+libxenguest.so.$(MAJOR).$(MINOR): $(GUEST_PIC_OBJS) libxenctrl.so
        $(CC) $(CFLAGS) $(LDFLAGS) -Wl,-soname -Wl,libxenguest.so.$(MAJOR) 
-shared -o $@ $^ -lz -lxenctrl
 
 -include $(DEPS)
diff -r 3be4c8288737 -r acabf4bdec4f tools/libxc/xc_core.c
--- a/tools/libxc/xc_core.c     Wed May 31 11:30:07 2006 -0600
+++ b/tools/libxc/xc_core.c     Wed May 31 13:05:21 2006 -0600
@@ -1,6 +1,4 @@
 #include "xg_private.h"
-#define ELFSIZE 32
-#include "xc_elf.h"
 #include <stdlib.h>
 #include <unistd.h>
 
diff -r 3be4c8288737 -r acabf4bdec4f tools/libxc/xc_csched.c
--- a/tools/libxc/xc_csched.c   Wed May 31 11:30:07 2006 -0600
+++ b/tools/libxc/xc_csched.c   Wed May 31 13:05:21 2006 -0600
@@ -12,10 +12,10 @@
 
 
 int
-xc_csched_domain_set(
+xc_sched_credit_domain_set(
     int xc_handle,
     uint32_t domid,
-    struct csched_domain *sdom)
+    struct sched_credit_adjdom *sdom)
 {
     DECLARE_DOM0_OP;
 
@@ -29,10 +29,10 @@ xc_csched_domain_set(
 }
 
 int
-xc_csched_domain_get(
+xc_sched_credit_domain_get(
     int xc_handle,
     uint32_t domid,
-    struct csched_domain *sdom)
+    struct sched_credit_adjdom *sdom)
 {
     DECLARE_DOM0_OP;
     int err;
diff -r 3be4c8288737 -r acabf4bdec4f tools/libxc/xc_hvm_build.c
--- a/tools/libxc/xc_hvm_build.c        Wed May 31 11:30:07 2006 -0600
+++ b/tools/libxc/xc_hvm_build.c        Wed May 31 13:05:21 2006 -0600
@@ -2,9 +2,9 @@
  * xc_hvm_build.c
  */
 
+#define ELFSIZE 32
 #include <stddef.h>
 #include "xg_private.h"
-#define ELFSIZE 32
 #include "xc_elf.h"
 #include <stdlib.h>
 #include <unistd.h>
diff -r 3be4c8288737 -r acabf4bdec4f tools/libxc/xc_linux_build.c
--- a/tools/libxc/xc_linux_build.c      Wed May 31 11:30:07 2006 -0600
+++ b/tools/libxc/xc_linux_build.c      Wed May 31 13:05:21 2006 -0600
@@ -5,14 +5,6 @@
 #include "xg_private.h"
 #include "xc_private.h"
 #include <xenctrl.h>
-
-#if defined(__i386__)
-#define ELFSIZE 32
-#endif
-
-#if defined(__x86_64__) || defined(__ia64__)
-#define ELFSIZE 64
-#endif
 
 #include "xc_elf.h"
 #include "xc_aout9.h"
diff -r 3be4c8288737 -r acabf4bdec4f tools/libxc/xc_load_elf.c
--- a/tools/libxc/xc_load_elf.c Wed May 31 11:30:07 2006 -0600
+++ b/tools/libxc/xc_load_elf.c Wed May 31 13:05:21 2006 -0600
@@ -3,14 +3,6 @@
  */
 
 #include "xg_private.h"
-
-#if defined(__i386__)
-#define ELFSIZE 32
-#endif
-#if defined(__x86_64__) || defined(__ia64__)
-#define ELFSIZE 64
-#endif
-
 #include "xc_elf.h"
 #include <stdlib.h>
 
diff -r 3be4c8288737 -r acabf4bdec4f tools/libxc/xenctrl.h
--- a/tools/libxc/xenctrl.h     Wed May 31 11:30:07 2006 -0600
+++ b/tools/libxc/xenctrl.h     Wed May 31 13:05:21 2006 -0600
@@ -354,13 +354,13 @@ int xc_sedf_domain_get(int xc_handle,
                        uint64_t *latency, uint16_t *extratime,
                        uint16_t *weight);
 
-int xc_csched_domain_set(int xc_handle,
-                         uint32_t domid,
-                         struct csched_domain *sdom);
-
-int xc_csched_domain_get(int xc_handle,
-                         uint32_t domid,
-                         struct csched_domain *sdom);
+int xc_sched_credit_domain_set(int xc_handle,
+                               uint32_t domid,
+                               struct sched_credit_adjdom *sdom);
+
+int xc_sched_credit_domain_get(int xc_handle,
+                               uint32_t domid,
+                               struct sched_credit_adjdom *sdom);
 
 typedef evtchn_status_t xc_evtchn_status_t;
 
diff -r 3be4c8288737 -r acabf4bdec4f tools/libxc/xg_private.c
--- a/tools/libxc/xg_private.c  Wed May 31 11:30:07 2006 -0600
+++ b/tools/libxc/xg_private.c  Wed May 31 13:05:21 2006 -0600
@@ -145,3 +145,18 @@ unsigned long csum_page(void *page)
 
     return sum ^ (sum>>32);
 }
+
+__attribute__((weak)) int xc_hvm_build(
+    int xc_handle,
+    uint32_t domid,
+    int memsize,
+    const char *image_name,
+    unsigned int vcpus,
+    unsigned int pae,
+    unsigned int acpi,
+    unsigned int apic,
+    unsigned int store_evtchn,
+    unsigned long *store_mfn)
+{
+    return -ENOSYS;
+}
diff -r 3be4c8288737 -r acabf4bdec4f tools/libxc/xg_private.h
--- a/tools/libxc/xg_private.h  Wed May 31 11:30:07 2006 -0600
+++ b/tools/libxc/xg_private.h  Wed May 31 13:05:21 2006 -0600
@@ -25,6 +25,14 @@
 #define DECLARE_DOM0_OP dom0_op_t op
 #endif
 
+#ifndef ELFSIZE
+#include <limits.h>
+#if UINT_MAX == ULONG_MAX
+#define ELFSIZE 32
+#else
+#define ELFSIZE 64
+#endif
+#endif
 
 char *xc_read_image(const char *filename, unsigned long *size);
 char *xc_inflate_buffer(const char *in_buf,
diff -r 3be4c8288737 -r acabf4bdec4f tools/misc/Makefile
--- a/tools/misc/Makefile       Wed May 31 11:30:07 2006 -0600
+++ b/tools/misc/Makefile       Wed May 31 13:05:21 2006 -0600
@@ -25,7 +25,7 @@ build: $(TARGETS)
 build: $(TARGETS)
        $(MAKE) -C miniterm
        $(MAKE) -C cpuperf
-ifneq ($(XEN_TARGET_ARCH),ia64)
+ifeq ($(CONFIG_MBOOTPACK),y)
        $(MAKE) -C mbootpack
 endif
        $(MAKE) -C lomount
diff -r 3be4c8288737 -r acabf4bdec4f tools/python/xen/lowlevel/xc/xc.c
--- a/tools/python/xen/lowlevel/xc/xc.c Wed May 31 11:30:07 2006 -0600
+++ b/tools/python/xen/lowlevel/xc/xc.c Wed May 31 13:05:21 2006 -0600
@@ -716,16 +716,16 @@ static PyObject *pyxc_sedf_domain_get(Xc
                          "weight",    weight);
 }
 
-static PyObject *pyxc_csched_domain_set(XcObject *self,
-                                        PyObject *args,
-                                        PyObject *kwds)
+static PyObject *pyxc_sched_credit_domain_set(XcObject *self,
+                                              PyObject *args,
+                                              PyObject *kwds)
 {
     uint32_t domid;
     uint16_t weight;
     uint16_t cap;
     static char *kwd_list[] = { "dom", "weight", "cap", NULL };
     static char kwd_type[] = "I|HH";
-    struct csched_domain sdom;
+    struct sched_credit_adjdom sdom;
     
     weight = 0;
     cap = (uint16_t)~0U;
@@ -736,22 +736,22 @@ static PyObject *pyxc_csched_domain_set(
     sdom.weight = weight;
     sdom.cap = cap;
 
-    if ( xc_csched_domain_set(self->xc_handle, domid, &sdom) != 0 )
-        return PyErr_SetFromErrno(xc_error);
-
-    Py_INCREF(zero);
-    return zero;
-}
-
-static PyObject *pyxc_csched_domain_get(XcObject *self, PyObject *args)
+    if ( xc_sched_credit_domain_set(self->xc_handle, domid, &sdom) != 0 )
+        return PyErr_SetFromErrno(xc_error);
+
+    Py_INCREF(zero);
+    return zero;
+}
+
+static PyObject *pyxc_sched_credit_domain_get(XcObject *self, PyObject *args)
 {
     uint32_t domid;
-    struct csched_domain sdom;
+    struct sched_credit_adjdom sdom;
     
     if( !PyArg_ParseTuple(args, "I", &domid) )
         return NULL;
     
-    if ( xc_csched_domain_get(self->xc_handle, domid, &sdom) != 0 )
+    if ( xc_sched_credit_domain_get(self->xc_handle, domid, &sdom) != 0 )
         return PyErr_SetFromErrno(xc_error);
 
     return Py_BuildValue("{s:H,s:H}",
@@ -1084,8 +1084,8 @@ static PyMethodDef pyxc_methods[] = {
       " latency   [long]: domain's wakeup latency hint\n"
       " extratime [int]:  domain aware of extratime?\n"},
     
-    { "csched_domain_set",
-      (PyCFunction)pyxc_csched_domain_set,
+    { "sched_credit_domain_set",
+      (PyCFunction)pyxc_sched_credit_domain_set,
       METH_KEYWORDS, "\n"
       "Set the scheduling parameters for a domain when running with the\n"
       "SMP credit scheduler.\n"
@@ -1093,8 +1093,8 @@ static PyMethodDef pyxc_methods[] = {
       " weight    [short]: domain's scheduling weight\n"
       "Returns: [int] 0 on success; -1 on error.\n" },
 
-    { "csched_domain_get",
-      (PyCFunction)pyxc_csched_domain_get,
+    { "sched_credit_domain_get",
+      (PyCFunction)pyxc_sched_credit_domain_get,
       METH_VARARGS, "\n"
       "Get the scheduling parameters for a domain when running with the\n"
       "SMP credit scheduler.\n"
diff -r 3be4c8288737 -r acabf4bdec4f tools/python/xen/xend/XendDomain.py
--- a/tools/python/xen/xend/XendDomain.py       Wed May 31 11:30:07 2006 -0600
+++ b/tools/python/xen/xend/XendDomain.py       Wed May 31 13:05:21 2006 -0600
@@ -522,25 +522,25 @@ class XendDomain:
         except Exception, ex:
             raise XendError(str(ex))
 
-    def domain_csched_get(self, domid):
+    def domain_sched_credit_get(self, domid):
         """Get credit scheduler parameters for a domain.
         """
         dominfo = self.domain_lookup_by_name_or_id_nr(domid)
         if not dominfo:
             raise XendInvalidDomain(str(domid))
         try:
-            return xc.csched_domain_get(dominfo.getDomid())
+            return xc.sched_credit_domain_get(dominfo.getDomid())
         except Exception, ex:
             raise XendError(str(ex))
     
-    def domain_csched_set(self, domid, weight, cap):
+    def domain_sched_credit_set(self, domid, weight, cap):
         """Set credit scheduler parameters for a domain.
         """
         dominfo = self.domain_lookup_by_name_or_id_nr(domid)
         if not dominfo:
             raise XendInvalidDomain(str(domid))
         try:
-            return xc.csched_domain_set(dominfo.getDomid(), weight, cap)
+            return xc.sched_credit_domain_set(dominfo.getDomid(), weight, cap)
         except Exception, ex:
             raise XendError(str(ex))
 
diff -r 3be4c8288737 -r acabf4bdec4f tools/python/xen/xend/server/SrvDomain.py
--- a/tools/python/xen/xend/server/SrvDomain.py Wed May 31 11:30:07 2006 -0600
+++ b/tools/python/xen/xend/server/SrvDomain.py Wed May 31 13:05:21 2006 -0600
@@ -132,15 +132,15 @@ class SrvDomain(SrvDir):
         val = fn(req.args, {'dom': self.dom.domid})
         return val
     
-    def op_domain_csched_get(self, _, req):
-        fn = FormFn(self.xd.domain_csched_get,
+    def op_domain_sched_credit_get(self, _, req):
+        fn = FormFn(self.xd.domain_sched_credit_get,
                     [['dom', 'int']])
         val = fn(req.args, {'dom': self.dom.domid})
         return val
 
 
-    def op_domain_csched_set(self, _, req):
-        fn = FormFn(self.xd.domain_csched_set,
+    def op_domain_sched_credit_set(self, _, req):
+        fn = FormFn(self.xd.domain_sched_credit_set,
                     [['dom', 'int'],
                      ['weight', 'int']])
         val = fn(req.args, {'dom': self.dom.domid})
diff -r 3be4c8288737 -r acabf4bdec4f tools/python/xen/xm/main.py
--- a/tools/python/xen/xm/main.py       Wed May 31 11:30:07 2006 -0600
+++ b/tools/python/xen/xm/main.py       Wed May 31 13:05:21 2006 -0600
@@ -99,7 +99,7 @@ sched_sedf_help = "sched-sedf [DOM] [OPT
                                     specifies another way of setting a 
domain's\n\
                                     cpu period/slice."
 
-csched_help = "csched                           Set or get credit scheduler 
parameters"
+sched_credit_help = "sched-credit                           Set or get credit 
scheduler parameters"
 block_attach_help = """block-attach <DomId> <BackDev> <FrontDev> <Mode>
                 [BackDomId]         Create a new virtual block device"""
 block_detach_help = """block-detach  <DomId> <DevId>    Destroy a domain's 
virtual block device,
@@ -175,7 +175,7 @@ host_commands = [
     ]
 
 scheduler_commands = [
-    "csched",
+    "sched-credit",
     "sched-bvt",
     "sched-bvt-ctxallow",
     "sched-sedf",
@@ -737,11 +737,11 @@ def xm_sched_sedf(args):
         else:
             print_sedf(sedf_info)
 
-def xm_csched(args):
-    usage_msg = """Csched:     Set or get credit scheduler parameters
+def xm_sched_credit(args):
+    usage_msg = """sched-credit:     Set or get credit scheduler parameters
  Usage:
 
-        csched -d domain [-w weight] [-c cap]
+        sched-credit -d domain [-w weight] [-c cap]
     """
     try:
         opts, args = getopt.getopt(args[0:], "d:w:c:",
@@ -769,14 +769,14 @@ def xm_csched(args):
         sys.exit(1)
 
     if weight is None and cap is None:
-        print server.xend.domain.csched_get(domain)
+        print server.xend.domain.sched_credit_get(domain)
     else:
         if weight is None:
             weight = int(0)
         if cap is None:
             cap = int(~0)
 
-        err = server.xend.domain.csched_set(domain, weight, cap)
+        err = server.xend.domain.sched_credit_set(domain, weight, cap)
         if err != 0:
             print err
 
@@ -806,7 +806,7 @@ def xm_top(args):
     os.execvp('xentop', ['xentop'])
 
 def xm_dmesg(args):
-    arg_check(args, "dmesg", 0)
+    arg_check(args, "dmesg", 0, 1)
     
     gopts = Opts(use="""[-c|--clear]
 
@@ -1076,7 +1076,7 @@ commands = {
     "sched-bvt": xm_sched_bvt,
     "sched-bvt-ctxallow": xm_sched_bvt_ctxallow,
     "sched-sedf": xm_sched_sedf,
-    "csched": xm_csched,
+    "sched-credit": xm_sched_credit,
     # block
     "block-attach": xm_block_attach,
     "block-detach": xm_block_detach,
diff -r 3be4c8288737 -r acabf4bdec4f tools/vtpm/Makefile
--- a/tools/vtpm/Makefile       Wed May 31 11:30:07 2006 -0600
+++ b/tools/vtpm/Makefile       Wed May 31 13:05:21 2006 -0600
@@ -9,7 +9,7 @@ VTPM_DIR = vtpm
 VTPM_DIR = vtpm
 
 # Emulator tarball name
-TPM_EMULATOR_TARFILE = tpm_emulator-0.2b.tar.gz
+TPM_EMULATOR_TARFILE = tpm_emulator-0.3.tar.gz
 
 GMP_HEADER = /usr/include/gmp.h
 
@@ -47,23 +47,23 @@ mrproper:
 
 # Create vtpm and TPM emulator dirs
 # apply patches for 1) used as dom0 tpm driver 2) used as vtpm device instance
-$(TPM_EMULATOR_DIR): $(TPM_EMULATOR_TARFILE) tpm_emulator.patch 
tpm_emulator-0.2b-x86_64.patch
+$(TPM_EMULATOR_DIR): $(TPM_EMULATOR_TARFILE) tpm_emulator.patch 
tpm_emulator-0.3-x86_64.patch
        if [ "$(BUILD_EMULATOR)" = "y" ]; then \
                tar -xzf $(TPM_EMULATOR_TARFILE); \
                rm -rf $(TPM_EMULATOR_DIR); \
-               mv tpm_emulator-0.2 $(TPM_EMULATOR_DIR); \
+               mv tpm_emulator-0.3 $(TPM_EMULATOR_DIR); \
                cd $(TPM_EMULATOR_DIR); \
-               patch -p1 < ../tpm_emulator-0.2b-x86_64.patch; \
+               patch -p1 < ../tpm_emulator-0.3-x86_64.patch; \
                patch -p1 <../tpm_emulator.patch; \
        fi
 
-$(VTPM_DIR): $(TPM_EMULATOR_TARFILE) tpm_emulator-0.2b-x86_64.patch vtpm.patch
+$(VTPM_DIR): $(TPM_EMULATOR_TARFILE) tpm_emulator-0.3-x86_64.patch vtpm.patch
        tar -xzf $(TPM_EMULATOR_TARFILE);  
        rm -rf $(VTPM_DIR)
-       mv tpm_emulator-0.2 $(VTPM_DIR); 
+       mv tpm_emulator-0.3 $(VTPM_DIR); 
 
        cd $(VTPM_DIR); \
-       patch -p1 < ../tpm_emulator-0.2b-x86_64.patch; \
+       patch -p1 < ../tpm_emulator-0.3-x86_64.patch; \
        patch -p1 <../vtpm.patch
 
 .PHONY: build_sub
diff -r 3be4c8288737 -r acabf4bdec4f tools/vtpm/Rules.mk
--- a/tools/vtpm/Rules.mk       Wed May 31 11:30:07 2006 -0600
+++ b/tools/vtpm/Rules.mk       Wed May 31 13:05:21 2006 -0600
@@ -33,6 +33,7 @@ OBJS  = $(patsubst %.c,%.o,$(SRCS))
 
 -include $(DEP_FILES)
 
+# Emulator does not work on 64-bit systems, and may be broken on 32 right now
 BUILD_EMULATOR = n
 
 # Make sure these are just rules
diff -r 3be4c8288737 -r acabf4bdec4f tools/vtpm/vtpm.patch
--- a/tools/vtpm/vtpm.patch     Wed May 31 11:30:07 2006 -0600
+++ b/tools/vtpm/vtpm.patch     Wed May 31 13:05:21 2006 -0600
@@ -1,23 +1,24 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
-diff -uprN orig/tpm_emulator-0.2-x86_64/AUTHORS vtpm/AUTHORS
---- orig/tpm_emulator-0.2-x86_64/AUTHORS       2005-08-15 00:58:57.000000000 
-0700
-+++ vtpm/AUTHORS       2006-05-17 09:31:11.000000000 -0700
-@@ -1 +1,2 @@
+diff -uprN orig/tpm_emulator-0.3-x86_64/AUTHORS vtpm/AUTHORS
+--- orig/tpm_emulator-0.3-x86_64/AUTHORS       2006-01-10 04:21:45.000000000 
-0800
++++ vtpm/AUTHORS       2006-05-30 12:23:26.000000000 -0700
+@@ -1,2 +1,3 @@
  Mario Strasser <mast@xxxxxxx>
-+INTEL Corp <>
-diff -uprN orig/tpm_emulator-0.2-x86_64/ChangeLog vtpm/ChangeLog
---- orig/tpm_emulator-0.2-x86_64/ChangeLog     2005-08-15 00:58:57.000000000 
-0700
-+++ vtpm/ChangeLog     2006-05-17 09:31:11.000000000 -0700
+ Heiko Stamer <stamer@xxxxxxxx> [DAA]
++INTEL Corp <> [VTPM Extensions]
+diff -uprN orig/tpm_emulator-0.3-x86_64/ChangeLog vtpm/ChangeLog
+--- orig/tpm_emulator-0.3-x86_64/ChangeLog     2006-01-10 04:21:45.000000000 
-0800
++++ vtpm/ChangeLog     2006-05-30 12:23:26.000000000 -0700
 @@ -1,3 +1,7 @@
 +2005-08-16 Intel Corp
-+      Moved module out of kernel to run as a ring 3 app
-+      Modified save_to_file and load_from_file to call a xen backend driver 
to call a VTPM manager
-+
- 2005-08-15  Mario Strasser <mast@xxxxxxx>
-       * all: some typos corrected
-       * tpm_integrity.c: bug in TPM_Extend fixed
-diff -uprN orig/tpm_emulator-0.2-x86_64/crypto/gmp_kernel_wrapper.c 
vtpm/crypto/gmp_kernel_wrapper.c
---- orig/tpm_emulator-0.2-x86_64/crypto/gmp_kernel_wrapper.c   2006-05-17 
09:34:13.000000000 -0700
-+++ vtpm/crypto/gmp_kernel_wrapper.c   2006-05-17 09:31:11.000000000 -0700
++      * Moved module out of kernel to run as a ring 3 app
++      * Modified save_to_file and load_from_file to call a xen backend driver 
to call a VTPM manager
++
+ 2005-12-24  Mario Strasser <mast@xxxxxxx>
+       * tpm_transport.c, tpm_marshalling.c, tpm_structures.h:
+               Transport session functionality added
+diff -uprN orig/tpm_emulator-0.3-x86_64/crypto/gmp_kernel_wrapper.c 
vtpm/crypto/gmp_kernel_wrapper.c
+--- orig/tpm_emulator-0.3-x86_64/crypto/gmp_kernel_wrapper.c   2006-05-30 
12:28:02.000000000 -0700
++++ vtpm/crypto/gmp_kernel_wrapper.c   2006-05-30 12:23:26.000000000 -0700
 @@ -1,5 +1,6 @@
  /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
   * Copyright (C) 2004 Mario Strasser <mast@xxxxxxx>,
@@ -77,9 +78,9 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
    }
  }
  
-diff -uprN orig/tpm_emulator-0.2-x86_64/crypto/rsa.c vtpm/crypto/rsa.c
---- orig/tpm_emulator-0.2-x86_64/crypto/rsa.c  2005-08-15 00:58:57.000000000 
-0700
-+++ vtpm/crypto/rsa.c  2006-05-17 09:31:11.000000000 -0700
+diff -uprN orig/tpm_emulator-0.3-x86_64/crypto/rsa.c vtpm/crypto/rsa.c
+--- orig/tpm_emulator-0.3-x86_64/crypto/rsa.c  2006-01-10 04:21:45.000000000 
-0800
++++ vtpm/crypto/rsa.c  2006-05-30 12:23:26.000000000 -0700
 @@ -1,5 +1,6 @@
  /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
   * Copyright (C) 2004 Mario Strasser <mast@xxxxxxx>,
@@ -87,7 +88,7 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
   *
   * This module is free software; you can redistribute it and/or modify
   * it under the terms of the GNU General Public License as published
-@@ -363,7 +364,7 @@ static int encode_message(int type, uint
+@@ -381,7 +382,7 @@ static int encode_message(int type, uint
        msg[0] = 0x00;
        get_random_bytes(&msg[1], SHA1_DIGEST_LENGTH);
        sha1_init(&ctx);
@@ -96,7 +97,7 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
        sha1_final(&ctx, &msg[1 + SHA1_DIGEST_LENGTH]);
        memset(&msg[1 + 2 * SHA1_DIGEST_LENGTH], 0x00, 
          msg_len - data_len - 2 * SHA1_DIGEST_LENGTH - 2);
-@@ -411,7 +412,7 @@ static int decode_message(int type, uint
+@@ -429,7 +430,7 @@ static int decode_message(int type, uint
        mask_generation(&msg[1], SHA1_DIGEST_LENGTH,
          &msg[1 + SHA1_DIGEST_LENGTH], msg_len - SHA1_DIGEST_LENGTH - 1);
        sha1_init(&ctx);
@@ -105,10 +106,10 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
        sha1_final(&ctx, &msg[1]);
        if (memcmp(&msg[1], &msg[1 + SHA1_DIGEST_LENGTH], 
            SHA1_DIGEST_LENGTH) != 0) return -1;
-diff -uprN orig/tpm_emulator-0.2-x86_64/linux_module.c vtpm/linux_module.c
---- orig/tpm_emulator-0.2-x86_64/linux_module.c        2006-05-17 
09:34:13.000000000 -0700
+diff -uprN orig/tpm_emulator-0.3-x86_64/linux_module.c vtpm/linux_module.c
+--- orig/tpm_emulator-0.3-x86_64/linux_module.c        2006-05-30 
12:28:02.000000000 -0700
 +++ vtpm/linux_module.c        1969-12-31 16:00:00.000000000 -0800
-@@ -1,163 +0,0 @@
+@@ -1,194 +0,0 @@
 -/* Software-Based Trusted Platform Module (TPM) Emulator for Linux 
 - * Copyright (C) 2004 Mario Strasser <mast@xxxxxxx>,
 - *
@@ -122,7 +123,7 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 - * GNU General Public License for more details.
 - *
-- * $Id: linux_module.c 19 2005-05-18 08:29:37Z mast $
+- * $Id: linux_module.c 76 2006-01-02 22:17:58Z hstamer $
 - */
 -
 -#include <linux/module.h>
@@ -140,11 +141,11 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
 -
 -/* module startup parameters */
 -char *startup = "save";
--MODULE_PARM(startup, "s");
+-module_param(startup, charp, 0444);
 -MODULE_PARM_DESC(startup, " Sets the startup mode of the TPM. "
 -  "Possible values are 'clear', 'save' (default) and 'deactivated.");
--char *storage_file = "/var/tpm/tpm_emulator-1.2.0.1";
--MODULE_PARM(storage_file, "s");
+-char *storage_file = "/var/tpm/tpm_emulator-1.2.0.2";
+-module_param(storage_file, charp, 0644);
 -MODULE_PARM_DESC(storage_file, " Sets the persistent-data storage " 
 -  "file of the TPM.");
 -
@@ -172,6 +173,12 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
 -{
 -  debug("%s()", __FUNCTION__);
 -  clear_bit(STATE_IS_OPEN, (void*)&module_state);
+-  down(&tpm_mutex);
+-  if (tpm_response.data != NULL) {
+-    kfree(tpm_response.data);
+-    tpm_response.data = NULL;
+-  }
+-  up(&tpm_mutex);
 -  return 0;
 -}
 -
@@ -183,6 +190,10 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
 -    count = min(count, (size_t)tpm_response.size - (size_t)*ppos);
 -    count -= copy_to_user(buf, &tpm_response.data[*ppos], count);
 -    *ppos += count;
+-    if ((size_t)tpm_response.size == (size_t)*ppos) {
+-      kfree(tpm_response.data);
+-      tpm_response.data = NULL;
+-    }
 -  } else {
 -    count = 0;
 -  }
@@ -205,9 +216,29 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
 -  return count;
 -}
 -
+-#define TPMIOC_CANCEL   _IO('T', 0x00)
+-#define TPMIOC_TRANSMIT _IO('T', 0x01)
+-
 -static int tpm_ioctl(struct inode *inode, struct file *file, unsigned int 
cmd, unsigned long arg)
 -{
--  debug("%s(%d, %ld)", __FUNCTION__, cmd, arg);
+-  debug("%s(%d, %p)", __FUNCTION__, cmd, (char*)arg);
+-  if (cmd == TPMIOC_TRANSMIT) {
+-    uint32_t count = ntohl(*(uint32_t*)(arg + 2));
+-    down(&tpm_mutex);
+-    if (tpm_response.data != NULL) kfree(tpm_response.data);
+-    if (tpm_handle_command((char*)arg, count, &tpm_response.data,
+-                           &tpm_response.size) == 0) {
+-      tpm_response.size -= copy_to_user((char*)arg, tpm_response.data,
+-                            tpm_response.size);
+-      kfree(tpm_response.data);
+-      tpm_response.data = NULL;
+-    } else {
+-      tpm_response.size = 0;
+-      tpm_response.data = NULL;
+-    }
+-    up(&tpm_mutex);
+-    return tpm_response.size;
+-  }
 -  return -1;
 -}
 -
@@ -240,7 +271,7 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
 -  /* initialize TPM emulator */
 -  if (!strcmp(startup, "clear")) {
 -    tpm_emulator_init(1);
--  } else if (!strcmp(startup, "save")) { 
+-  } else if (!strcmp(startup, "save")) {
 -    tpm_emulator_init(2);
 -  } else if (!strcmp(startup, "deactivated")) {
 -    tpm_emulator_init(3);
@@ -257,6 +288,7 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
 -{
 -  tpm_emulator_shutdown();
 -  misc_deregister(&tpm_dev);
+-  if (tpm_response.data != NULL) kfree(tpm_response.data);
 -}
 -
 -module_init(init_tpm_module);
@@ -264,7 +296,7 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
 -
 -uint64_t tpm_get_ticks(void)
 -{
--  static struct timespec old_time = {0, 0}; 
+-  static struct timespec old_time = {0, 0};
 -  struct timespec new_time = current_kernel_time();
 -  uint64_t ticks = (uint64_t)(old_time.tv_sec - new_time.tv_sec) * 1000000
 -                   + (old_time.tv_nsec - new_time.tv_nsec) / 1000;
@@ -272,9 +304,9 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
 -  return (ticks > 0) ? ticks : 1;
 -}
 -
-diff -uprN orig/tpm_emulator-0.2-x86_64/linux_module.h vtpm/linux_module.h
---- orig/tpm_emulator-0.2-x86_64/linux_module.h        2006-05-17 
09:34:13.000000000 -0700
-+++ vtpm/linux_module.h        2006-05-17 09:31:11.000000000 -0700
+diff -uprN orig/tpm_emulator-0.3-x86_64/linux_module.h vtpm/linux_module.h
+--- orig/tpm_emulator-0.3-x86_64/linux_module.h        2006-05-30 
12:28:02.000000000 -0700
++++ vtpm/linux_module.h        2006-05-30 12:23:26.000000000 -0700
 @@ -1,5 +1,6 @@
  /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
   * Copyright (C) 2004 Mario Strasser <mast@xxxxxxx>,
@@ -374,15 +406,15 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
  #define BE16_TO_CPU(x) __be16_to_cpu(x)
  #define LE16_TO_CPU(x) __le16_to_cpu(x)
  
-diff -uprN orig/tpm_emulator-0.2-x86_64/Makefile vtpm/Makefile
---- orig/tpm_emulator-0.2-x86_64/Makefile      2006-05-17 09:34:13.000000000 
-0700
-+++ vtpm/Makefile      2006-05-17 09:31:11.000000000 -0700
+diff -uprN orig/tpm_emulator-0.3-x86_64/Makefile vtpm/Makefile
+--- orig/tpm_emulator-0.3-x86_64/Makefile      2006-05-30 12:28:02.000000000 
-0700
++++ vtpm/Makefile      2006-05-30 12:23:26.000000000 -0700
 @@ -1,22 +1,31 @@
  # Software-Based Trusted Platform Module (TPM) Emulator for Linux
  # Copyright (C) 2004 Mario Strasser <mast@xxxxxxx>
-+# Copyright (C) 2005 INTEL Corp.
++# Copyright (C) 2006 INTEL Corp.
  #
- # $Id: Makefile 10 2005-04-26 20:59:50Z mast $
+ # $Id: Makefile 69 2005-12-13 12:55:52Z mast $
  
 -# kernel settings
 -KERNEL_RELEASE := $(shell uname -r)
@@ -394,11 +426,11 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
 -MODULE_NAME    := tpm_emulator
 +BIN            := vtpmd
  VERSION_MAJOR  := 0
- VERSION_MINOR  := 2
+ VERSION_MINOR  := 3
  VERSION_BUILD  := $(shell date +"%s")
  
 -# enable/disable DEBUG messages
--EXTRA_CFLAGS   += -DDEBUG -g  
+-EXTRA_CFLAGS   += -Wall -DDEBUG -g  
 +# Installation program and options
 +INSTALL         = install
 +INSTALL_PROG    = $(INSTALL) -m0755
@@ -468,10 +500,10 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
  
  $(src)/crypto/libgmp.a:
        test -f $(src)/crypto/libgmp.a || ln -s $(GMP_LIB) 
$(src)/crypto/libgmp.a
-diff -uprN orig/tpm_emulator-0.2-x86_64/README vtpm/README
---- orig/tpm_emulator-0.2-x86_64/README        2006-05-17 09:34:13.000000000 
-0700
-+++ vtpm/README        2006-05-17 09:31:11.000000000 -0700
-@@ -13,7 +13,8 @@ $Id: README 8 2005-01-25 21:11:45Z jmoli
+diff -uprN orig/tpm_emulator-0.3-x86_64/README vtpm/README
+--- orig/tpm_emulator-0.3-x86_64/README        2006-05-30 12:28:02.000000000 
-0700
++++ vtpm/README        2006-05-30 12:23:26.000000000 -0700
+@@ -13,7 +13,8 @@ $Id: README 78 2006-01-07 10:45:39Z mast
  Copyright
  --------------------------------------------------------------------------
  Copyright (C) 2004 Mario Strasser <mast@xxxxxxx> and Swiss Federal 
@@ -481,9 +513,9 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
                
  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
-diff -uprN orig/tpm_emulator-0.2-x86_64/tpm/tpm_audit.c vtpm/tpm/tpm_audit.c
---- orig/tpm_emulator-0.2-x86_64/tpm/tpm_audit.c       2005-08-15 
00:58:57.000000000 -0700
-+++ vtpm/tpm/tpm_audit.c       2006-05-17 09:31:11.000000000 -0700
+diff -uprN orig/tpm_emulator-0.3-x86_64/tpm/tpm_audit.c vtpm/tpm/tpm_audit.c
+--- orig/tpm_emulator-0.3-x86_64/tpm/tpm_audit.c       2006-01-10 
04:21:45.000000000 -0800
++++ vtpm/tpm/tpm_audit.c       2006-05-30 12:23:26.000000000 -0700
 @@ -1,6 +1,7 @@
  /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
   * Copyright (C) 2004 Mario Strasser <mast@xxxxxxx>,
@@ -546,9 +578,9 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
    return TPM_SUCCESS;
  }
 -
-diff -uprN orig/tpm_emulator-0.2-x86_64/tpm/tpm_authorization.c 
vtpm/tpm/tpm_authorization.c
---- orig/tpm_emulator-0.2-x86_64/tpm/tpm_authorization.c       2005-08-15 
00:58:57.000000000 -0700
-+++ vtpm/tpm/tpm_authorization.c       2006-05-17 09:31:11.000000000 -0700
+diff -uprN orig/tpm_emulator-0.3-x86_64/tpm/tpm_authorization.c 
vtpm/tpm/tpm_authorization.c
+--- orig/tpm_emulator-0.3-x86_64/tpm/tpm_authorization.c       2006-01-10 
04:21:45.000000000 -0800
++++ vtpm/tpm/tpm_authorization.c       2006-05-30 12:23:26.000000000 -0700
 @@ -1,6 +1,7 @@
  /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
   * Copyright (C) 2004 Mario Strasser <mast@xxxxxxx>,
@@ -557,7 +589,7 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
   *
   * This module is free software; you can redistribute it and/or modify
   * it under the terms of the GNU General Public License as published
-@@ -268,7 +269,7 @@ TPM_RESULT tpm_verify_auth(TPM_AUTH *aut
+@@ -279,7 +280,7 @@ TPM_RESULT tpm_verify_auth(TPM_AUTH *aut
  {
    hmac_ctx_t ctx;
    TPM_SESSION_DATA *session;
@@ -565,16 +597,10 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
 +  UINT32 auth_handle = CPU_TO_BE32(auth->authHandle);
    
    info("tpm_verify_auth(%08x)", auth->authHandle);
-   /* get dedicated authorization session */
-@@ -316,5 +317,3 @@ void tpm_decrypt_auth_secret(TPM_ENCAUTH
-   for (i = 0; i < sizeof(TPM_SECRET); i++)
-     plainAuth[i] ^= encAuth[i];
- }
--
--
-diff -uprN orig/tpm_emulator-0.2-x86_64/tpm/tpm_capability.c 
vtpm/tpm/tpm_capability.c
---- orig/tpm_emulator-0.2-x86_64/tpm/tpm_capability.c  2005-08-15 
00:58:57.000000000 -0700
-+++ vtpm/tpm/tpm_capability.c  2006-05-17 09:31:11.000000000 -0700
+   /* get dedicated authorization or transport session */
+diff -uprN orig/tpm_emulator-0.3-x86_64/tpm/tpm_capability.c 
vtpm/tpm/tpm_capability.c
+--- orig/tpm_emulator-0.3-x86_64/tpm/tpm_capability.c  2006-01-10 
04:21:45.000000000 -0800
++++ vtpm/tpm/tpm_capability.c  2006-05-30 12:23:26.000000000 -0700
 @@ -1,6 +1,7 @@
  /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
   * Copyright (C) 2004 Mario Strasser <mast@xxxxxxx>,
@@ -583,7 +609,7 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
   *
   * This module is free software; you can redistribute it and/or modify
   * it under the terms of the GNU General Public License as published
-@@ -398,7 +399,7 @@ TPM_RESULT TPM_GetCapability(TPM_CAPABIL
+@@ -406,7 +407,7 @@ TPM_RESULT TPM_GetCapability(TPM_CAPABIL
  
      case TPM_CAP_KEY_HANDLE:
        debug("[TPM_CAP_KEY_HANDLE]");
@@ -592,14 +618,14 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
        return cap_handle(4, (BYTE*)&subCapSize, respSize, resp);
  
      case TPM_CAP_CHECK_LOADED:
-@@ -472,4 +473,3 @@ TPM_RESULT TPM_GetCapability(TPM_CAPABIL
+@@ -480,4 +481,3 @@ TPM_RESULT TPM_GetCapability(TPM_CAPABIL
        return TPM_BAD_MODE;
    }
  }
 -
-diff -uprN orig/tpm_emulator-0.2-x86_64/tpm/tpm_cmd_handler.c 
vtpm/tpm/tpm_cmd_handler.c
---- orig/tpm_emulator-0.2-x86_64/tpm/tpm_cmd_handler.c 2005-08-15 
00:58:57.000000000 -0700
-+++ vtpm/tpm/tpm_cmd_handler.c 2006-05-17 09:31:11.000000000 -0700
+diff -uprN orig/tpm_emulator-0.3-x86_64/tpm/tpm_cmd_handler.c 
vtpm/tpm/tpm_cmd_handler.c
+--- orig/tpm_emulator-0.3-x86_64/tpm/tpm_cmd_handler.c 2006-01-10 
04:21:45.000000000 -0800
++++ vtpm/tpm/tpm_cmd_handler.c 2006-05-30 12:23:26.000000000 -0700
 @@ -1,6 +1,7 @@
  /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
   * Copyright (C) 2004 Mario Strasser <mast@xxxxxxx>,
@@ -608,17 +634,17 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
   *
   * This module is free software; you can redistribute it and/or modify
   * it under the terms of the GNU General Public License as published
-@@ -26,7 +27,7 @@ static void tpm_compute_in_param_digest(
+@@ -73,7 +74,7 @@ void tpm_compute_in_param_digest(TPM_REQ
  {
    sha1_ctx_t sha1;
-   UINT32 offset;
+   UINT32 offset = tpm_get_param_offset(req->ordinal);
 -  UINT32 ord = cpu_to_be32(req->ordinal);
 +  UINT32 ord = CPU_TO_BE32(req->ordinal);
  
-   /* skip all key-handles at the beginning */
-   switch (req->ordinal) {
-@@ -82,8 +83,8 @@ static void tpm_compute_in_param_digest(
- static void tpm_compute_out_param_digest(TPM_COMMAND_CODE ordinal, 
TPM_RESPONSE *rsp)
+   /* compute SHA1 hash */
+   if (offset <= req->paramSize) {
+@@ -89,8 +90,8 @@ void tpm_compute_in_param_digest(TPM_REQ
+ void tpm_compute_out_param_digest(TPM_COMMAND_CODE ordinal, TPM_RESPONSE *rsp)
  {
    sha1_ctx_t sha1;
 -  UINT32 res = cpu_to_be32(rsp->result);
@@ -628,7 +654,7 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
  
    /* compute SHA1 hash */
    sha1_init(&sha1);
-@@ -3081,7 +3082,7 @@ static void tpm_setup_rsp_auth(TPM_COMMA
+@@ -3123,7 +3124,7 @@ static void tpm_setup_rsp_auth(TPM_COMMA
        hmac_update(&hmac, rsp->auth2->digest, sizeof(rsp->auth2->digest));
  #if 0
        if (tpm_get_auth(rsp->auth2->authHandle)->type == TPM_ST_OIAP) {
@@ -637,7 +663,7 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
          hmac_update(&hmac, (BYTE*)&handle, 4);
        }
  #endif
-@@ -3096,7 +3097,7 @@ static void tpm_setup_rsp_auth(TPM_COMMA
+@@ -3138,7 +3139,7 @@ static void tpm_setup_rsp_auth(TPM_COMMA
        hmac_update(&hmac, rsp->auth1->digest, sizeof(rsp->auth1->digest));
  #if 0
        if (tpm_get_auth(rsp->auth1->authHandle)->type == TPM_ST_OIAP) {
@@ -646,25 +672,20 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
          hmac_update(&hmac, (BYTE*)&handle, 4);
        }
  #endif
-@@ -3179,7 +3180,9 @@ extern const char *tpm_error_to_string(T
- static void tpm_execute_command(TPM_REQUEST *req, TPM_RESPONSE *rsp)
+@@ -3221,7 +3222,9 @@ extern const char *tpm_error_to_string(T
+ void tpm_execute_command(TPM_REQUEST *req, TPM_RESPONSE *rsp)
  {
    TPM_RESULT res;
 -  
 +
-+  req->tag = (BYTE) req->tag;  // VIN HACK!!! 
++  req->tag = (BYTE) req->tag;  // FIXME: Why is this here
 +
    /* setup authorisation as well as response tag and size */
    memset(rsp, 0, sizeof(*rsp));
    switch (req->tag) {
-@@ -3878,4 +3881,3 @@ int tpm_handle_command(const uint8_t *in
-   tpm_free(rsp.param);
-   return 0;
- }
--
-diff -uprN orig/tpm_emulator-0.2-x86_64/tpm/tpm_crypto.c vtpm/tpm/tpm_crypto.c
---- orig/tpm_emulator-0.2-x86_64/tpm/tpm_crypto.c      2006-05-17 
09:34:13.000000000 -0700
-+++ vtpm/tpm/tpm_crypto.c      2006-05-17 09:31:11.000000000 -0700
+diff -uprN orig/tpm_emulator-0.3-x86_64/tpm/tpm_crypto.c vtpm/tpm/tpm_crypto.c
+--- orig/tpm_emulator-0.3-x86_64/tpm/tpm_crypto.c      2006-05-30 
12:28:02.000000000 -0700
++++ vtpm/tpm/tpm_crypto.c      2006-05-30 12:23:26.000000000 -0700
 @@ -1,6 +1,7 @@
  /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
   * Copyright (C) 2004 Mario Strasser <mast@xxxxxxx>,
@@ -683,13 +704,170 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
      if (rsa_sign(&key->key, RSA_SSA_PKCS1_SHA1, 
          buf, areaToSignSize + 30, *sig)) {
 @@ -383,4 +384,3 @@ TPM_RESULT TPM_CertifyKey2(TPM_KEY_HANDL
-   }  
+   }
    return TPM_SUCCESS;
  }
 -
-diff -uprN orig/tpm_emulator-0.2-x86_64/tpm/tpm_data.c vtpm/tpm/tpm_data.c
---- orig/tpm_emulator-0.2-x86_64/tpm/tpm_data.c        2006-05-17 
09:34:13.000000000 -0700
-+++ vtpm/tpm/tpm_data.c        2006-05-17 09:31:11.000000000 -0700
+diff -uprN orig/tpm_emulator-0.3-x86_64/tpm/tpm_daa.c vtpm/tpm/tpm_daa.c
+--- orig/tpm_emulator-0.3-x86_64/tpm/tpm_daa.c 2006-01-10 04:21:45.000000000 
-0800
++++ vtpm/tpm/tpm_daa.c 2006-05-30 12:23:26.000000000 -0700
+@@ -700,14 +700,14 @@ info("tested until here");
+           sizeof(session->DAA_tpmSpecific.DAA_rekey));
+       sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count, 
+           sizeof(session->DAA_tpmSpecific.DAA_count));
+-      sha1_update(&sha1, "\x00", 1);
++      sha1_update(&sha1, (BYTE *) "\x00", 1);
+       sha1_final(&sha1, scratch);
+       sha1_init(&sha1);
+       sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_rekey, 
+           sizeof(session->DAA_tpmSpecific.DAA_rekey));
+       sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count, 
+           sizeof(session->DAA_tpmSpecific.DAA_count));
+-      sha1_update(&sha1, "\x01", 1);
++      sha1_update(&sha1, (BYTE *) "\x01", 1);
+       sha1_final(&sha1, scratch + SHA1_DIGEST_LENGTH);
+       mpz_init(f), mpz_init(q);
+       mpz_import(f, 2 * SHA1_DIGEST_LENGTH, 1, 1, 0, 0, scratch);
+@@ -787,14 +787,14 @@ info("tested until here");
+           sizeof(session->DAA_tpmSpecific.DAA_rekey));
+       sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count, 
+           sizeof(session->DAA_tpmSpecific.DAA_count));
+-      sha1_update(&sha1, "\x00", 1);
++      sha1_update(&sha1, (BYTE *) "\x00", 1);
+       sha1_final(&sha1, scratch);
+       sha1_init(&sha1);
+       sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_rekey, 
+           sizeof(session->DAA_tpmSpecific.DAA_rekey));
+       sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count, 
+           sizeof(session->DAA_tpmSpecific.DAA_count));
+-      sha1_update(&sha1, "\x01", 1);
++      sha1_update(&sha1, (BYTE *) "\x01", 1);
+       sha1_final(&sha1, scratch + SHA1_DIGEST_LENGTH);
+       mpz_init(f), mpz_init(q);
+       mpz_import(f, 2 * SHA1_DIGEST_LENGTH, 1, 1, 0, 0, scratch);
+@@ -1440,14 +1440,14 @@ info("tested until here");
+           sizeof(session->DAA_tpmSpecific.DAA_rekey));
+       sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count, 
+           sizeof(session->DAA_tpmSpecific.DAA_count));
+-      sha1_update(&sha1, "\x00", 1);
++      sha1_update(&sha1, (BYTE *) "\x00", 1);
+       sha1_final(&sha1, scratch);
+       sha1_init(&sha1);
+       sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_rekey, 
+           sizeof(session->DAA_tpmSpecific.DAA_rekey));
+       sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count, 
+           sizeof(session->DAA_tpmSpecific.DAA_count));
+-      sha1_update(&sha1, "\x01", 1);
++      sha1_update(&sha1, (BYTE *) "\x01", 1);
+       sha1_final(&sha1, scratch + SHA1_DIGEST_LENGTH);
+       mpz_init(f), mpz_init(q);
+       mpz_import(f, 2 * SHA1_DIGEST_LENGTH, 1, 1, 0, 0, scratch);
+@@ -1660,14 +1660,14 @@ info("tested until here");
+           sizeof(session->DAA_tpmSpecific.DAA_rekey));
+       sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count, 
+           sizeof(session->DAA_tpmSpecific.DAA_count));
+-      sha1_update(&sha1, "\x00", 1);
++      sha1_update(&sha1, (BYTE *) "\x00", 1);
+       sha1_final(&sha1, scratch);
+       sha1_init(&sha1);
+       sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_rekey, 
+           sizeof(session->DAA_tpmSpecific.DAA_rekey));
+       sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count, 
+           sizeof(session->DAA_tpmSpecific.DAA_count));
+-      sha1_update(&sha1, "\x01", 1);
++      sha1_update(&sha1, (BYTE *) "\x01", 1);
+       sha1_final(&sha1, scratch + SHA1_DIGEST_LENGTH);
+       mpz_init(f), mpz_init(q);
+       mpz_import(f, 2 * SHA1_DIGEST_LENGTH, 1, 1, 0, 0, scratch);
+@@ -1740,14 +1740,14 @@ info("tested until here");
+           sizeof(session->DAA_tpmSpecific.DAA_rekey));
+       sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count, 
+           sizeof(session->DAA_tpmSpecific.DAA_count));
+-      sha1_update(&sha1, "\x00", 1);
++      sha1_update(&sha1, (BYTE *) "\x00", 1);
+       sha1_final(&sha1, scratch);
+       sha1_init(&sha1);
+       sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_rekey, 
+           sizeof(session->DAA_tpmSpecific.DAA_rekey));
+       sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count, 
+           sizeof(session->DAA_tpmSpecific.DAA_count));
+-      sha1_update(&sha1, "\x01", 1);
++      sha1_update(&sha1, (BYTE *) "\x01", 1);
+       sha1_final(&sha1, scratch + SHA1_DIGEST_LENGTH);
+       mpz_init(f), mpz_init(q);
+       mpz_import(f, 2 * SHA1_DIGEST_LENGTH, 1, 1, 0, 0, scratch);
+@@ -2828,14 +2828,14 @@ TPM_RESULT TPM_DAA_Sign(TPM_HANDLE handl
+           sizeof(session->DAA_tpmSpecific.DAA_rekey));
+       sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count, 
+           sizeof(session->DAA_tpmSpecific.DAA_count));
+-      sha1_update(&sha1, "\x00", 1);
++      sha1_update(&sha1, (BYTE *) "\x00", 1);
+       sha1_final(&sha1, scratch);
+       sha1_init(&sha1);
+       sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_rekey, 
+           sizeof(session->DAA_tpmSpecific.DAA_rekey));
+       sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count, 
+           sizeof(session->DAA_tpmSpecific.DAA_count));
+-      sha1_update(&sha1, "\x01", 1);
++      sha1_update(&sha1, (BYTE *) "\x01", 1);
+       sha1_final(&sha1, scratch + SHA1_DIGEST_LENGTH);
+       mpz_init(f), mpz_init(q);
+       mpz_import(f, 2 * SHA1_DIGEST_LENGTH, 1, 1, 0, 0, scratch);
+@@ -3050,7 +3050,7 @@ TPM_RESULT TPM_DAA_Sign(TPM_HANDLE handl
+         sha1_init(&sha1);
+         sha1_update(&sha1, (BYTE*) &session->DAA_session.DAA_digest, 
+           sizeof(session->DAA_session.DAA_digest));
+-        sha1_update(&sha1, "\x01", 1);
++        sha1_update(&sha1, (BYTE *) "\x01", 1);
+         sha1_update(&sha1, inputData1, inputSize1);
+         sha1_final(&sha1, (BYTE*) &session->DAA_session.DAA_digest);
+       }
+@@ -3078,7 +3078,7 @@ TPM_RESULT TPM_DAA_Sign(TPM_HANDLE handl
+         sha1_init(&sha1);
+         sha1_update(&sha1, (BYTE*) &session->DAA_session.DAA_digest, 
+           sizeof(session->DAA_session.DAA_digest));
+-        sha1_update(&sha1, "\x01", 1);
++        sha1_update(&sha1, (BYTE *) "\x01", 1);
+         rsa_export_modulus(&aikData->key, scratch, &size);
+         sha1_update(&sha1, scratch, size);
+         sha1_final(&sha1, (BYTE*) &session->DAA_session.DAA_digest);
+@@ -3134,14 +3134,14 @@ TPM_RESULT TPM_DAA_Sign(TPM_HANDLE handl
+           sizeof(session->DAA_tpmSpecific.DAA_rekey));
+       sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count, 
+           sizeof(session->DAA_tpmSpecific.DAA_count));
+-      sha1_update(&sha1, "\x00", 1);
++      sha1_update(&sha1, (BYTE *) "\x00", 1);
+       sha1_final(&sha1, scratch);
+       sha1_init(&sha1);
+       sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_rekey, 
+           sizeof(session->DAA_tpmSpecific.DAA_rekey));
+       sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count, 
+           sizeof(session->DAA_tpmSpecific.DAA_count));
+-      sha1_update(&sha1, "\x01", 1);
++      sha1_update(&sha1, (BYTE *) "\x01", 1);
+       sha1_final(&sha1, scratch + SHA1_DIGEST_LENGTH);
+       mpz_init(f), mpz_init(q);
+       mpz_import(f, 2 * SHA1_DIGEST_LENGTH, 1, 1, 0, 0, scratch);
+@@ -3213,14 +3213,14 @@ TPM_RESULT TPM_DAA_Sign(TPM_HANDLE handl
+           sizeof(session->DAA_tpmSpecific.DAA_rekey));
+       sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count, 
+           sizeof(session->DAA_tpmSpecific.DAA_count));
+-      sha1_update(&sha1, "\x00", 1);
++      sha1_update(&sha1, (BYTE *) "\x00", 1);
+       sha1_final(&sha1, scratch);
+       sha1_init(&sha1);
+       sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_rekey, 
+           sizeof(session->DAA_tpmSpecific.DAA_rekey));
+       sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count, 
+           sizeof(session->DAA_tpmSpecific.DAA_count));
+-      sha1_update(&sha1, "\x01", 1);
++      sha1_update(&sha1, (BYTE *) "\x01", 1);
+       sha1_final(&sha1, scratch + SHA1_DIGEST_LENGTH);
+       mpz_init(f), mpz_init(q);
+       mpz_import(f, 2 * SHA1_DIGEST_LENGTH, 1, 1, 0, 0, scratch);
+diff -uprN orig/tpm_emulator-0.3-x86_64/tpm/tpm_data.c vtpm/tpm/tpm_data.c
+--- orig/tpm_emulator-0.3-x86_64/tpm/tpm_data.c        2006-05-30 
12:28:02.000000000 -0700
++++ vtpm/tpm/tpm_data.c        2006-05-30 12:23:26.000000000 -0700
 @@ -1,6 +1,7 @@
  /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
   * Copyright (C) 2004 Mario Strasser <mast@xxxxxxx>,
@@ -698,8 +876,8 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
   *
   * This module is free software; you can redistribute it and/or modify
   * it under the terms of the GNU General Public License as published
-@@ -15,9 +16,15 @@
-  * $Id: tpm_data.c 9 2005-04-26 18:15:31Z mast $
+@@ -15,10 +16,15 @@
+  * $Id: tpm_data.c 36 2005-10-26 20:31:19Z hstamer $
   */
  
 +#include <sys/types.h>
@@ -710,11 +888,12 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
  #include "tpm_emulator.h"
  #include "tpm_structures.h"
  #include "tpm_marshalling.h"
+-#include "linux_module.h"
 +#include "vtpm_manager.h"
  
  TPM_DATA tpmData;
  
-@@ -28,6 +35,7 @@ BOOL tpm_get_physical_presence(void)
+@@ -39,6 +45,7 @@ static inline void init_pcr_attr(int pcr
  
  void tpm_init_data(void)
  {
@@ -722,7 +901,7 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
    /* endorsement key */
    uint8_t ek_n[] =  "\xa8\xdb\xa9\x42\xa8\xf3\xb8\x06\x85\x90\x76\x93\xad\xf7"
      "\x74\xec\x3f\xd3\x3d\x9d\xe8\x2e\xff\x15\xed\x0e\xce\x5f\x93"
-@@ -66,6 +74,8 @@ void tpm_init_data(void)
+@@ -77,6 +84,8 @@ void tpm_init_data(void)
      "\xd1\xc0\x8b\x5b\xa2\x2e\xa7\x15\xca\x50\x75\x10\x48\x9c\x2b"
      "\x18\xb9\x67\x8f\x5d\x64\xc3\x28\x9f\x2f\x16\x2f\x08\xda\x47"
      "\xec\x86\x43\x0c\x80\x99\x07\x34\x0f";
@@ -731,18 +910,7 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
    int i;
    /* reset all data to NULL, FALSE or 0 */
    memset(&tpmData, 0, sizeof(tpmData));
-@@ -85,6 +95,10 @@ void tpm_init_data(void)
-   tpmData.permanent.data.version.revMinor = VERSION_MINOR;
-   /* setup PCR attributes */
-   for (i = 0; i < TPM_NUM_PCR; i++) {
-+    int j;
-+    for (j=0; j < TPM_NUM_LOCALITY; j++) {
-+      tpmData.permanent.data.pcrAttrib[i].pcrExtendLocal[j] = TRUE;
-+    }
-     tpmData.permanent.data.pcrAttrib[i].pcrReset = TRUE;
-   }
-   /* set tick type */
-@@ -115,49 +129,235 @@ void tpm_release_data(void)
+@@ -150,49 +159,235 @@ void tpm_release_data(void)
  
  #ifdef TPM_STORE_TO_FILE
  
@@ -1009,7 +1177,7 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
  }
  
  #else
-@@ -232,7 +432,6 @@ int tpm_restore_permanent_data(void)
+@@ -267,7 +462,6 @@ int tpm_restore_permanent_data(void)
  
  int tpm_erase_permanent_data(void)
  {
@@ -1018,9 +1186,9 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
    return res;
  }
 -
-diff -uprN orig/tpm_emulator-0.2-x86_64/tpm/tpm_deprecated.c 
vtpm/tpm/tpm_deprecated.c
---- orig/tpm_emulator-0.2-x86_64/tpm/tpm_deprecated.c  2005-08-15 
00:58:57.000000000 -0700
-+++ vtpm/tpm/tpm_deprecated.c  2006-05-17 09:31:11.000000000 -0700
+diff -uprN orig/tpm_emulator-0.3-x86_64/tpm/tpm_deprecated.c 
vtpm/tpm/tpm_deprecated.c
+--- orig/tpm_emulator-0.3-x86_64/tpm/tpm_deprecated.c  2006-01-10 
04:21:45.000000000 -0800
++++ vtpm/tpm/tpm_deprecated.c  2006-05-30 12:23:26.000000000 -0700
 @@ -1,6 +1,7 @@
  /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
   * Copyright (C) 2004 Mario Strasser <mast@xxxxxxx>,
@@ -1047,9 +1215,9 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
                          authContextSize, &contextBlob);
    if (res != TPM_SUCCESS) return res;
    len = *authContextSize;
-diff -uprN orig/tpm_emulator-0.2-x86_64/tpm/tpm_emulator.h 
vtpm/tpm/tpm_emulator.h
---- orig/tpm_emulator-0.2-x86_64/tpm/tpm_emulator.h    2005-08-15 
00:58:57.000000000 -0700
-+++ vtpm/tpm/tpm_emulator.h    2006-05-17 09:31:11.000000000 -0700
+diff -uprN orig/tpm_emulator-0.3-x86_64/tpm/tpm_emulator.h 
vtpm/tpm/tpm_emulator.h
+--- orig/tpm_emulator-0.3-x86_64/tpm/tpm_emulator.h    2006-01-10 
04:21:45.000000000 -0800
++++ vtpm/tpm/tpm_emulator.h    2006-05-30 12:23:26.000000000 -0700
 @@ -1,5 +1,6 @@
  /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
   * Copyright (C) 2004 Mario Strasser <mast@xxxxxxx>,
@@ -1064,12 +1232,12 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
 -#undef  TPM_GENERATE_EK
 +//#undef  TPM_GENERATE_EK
 +#define  TPM_GENERATE_EK
- 
- /**
-  * tpm_emulator_init - initialises and starts the TPM emulator
-diff -uprN orig/tpm_emulator-0.2-x86_64/tpm/tpm_integrity.c 
vtpm/tpm/tpm_integrity.c
---- orig/tpm_emulator-0.2-x86_64/tpm/tpm_integrity.c   2005-08-15 
00:58:57.000000000 -0700
-+++ vtpm/tpm/tpm_integrity.c   2006-05-17 09:31:11.000000000 -0700
+ #undef  TPM_GENERATE_SEED_DAA
+ 
+ #define TPM_MANUFACTURER 0x4554485A /* 'ETHZ' */        
+diff -uprN orig/tpm_emulator-0.3-x86_64/tpm/tpm_integrity.c 
vtpm/tpm/tpm_integrity.c
+--- orig/tpm_emulator-0.3-x86_64/tpm/tpm_integrity.c   2006-01-10 
04:21:45.000000000 -0800
++++ vtpm/tpm/tpm_integrity.c   2006-05-30 12:23:26.000000000 -0700
 @@ -1,6 +1,7 @@
  /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
   * Copyright (C) 2004 Mario Strasser <mast@xxxxxxx>,
@@ -1083,9 +1251,9 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
    return TPM_SUCCESS;
  }
 -
-diff -uprN orig/tpm_emulator-0.2-x86_64/tpm/tpm_structures.h 
vtpm/tpm/tpm_structures.h
---- orig/tpm_emulator-0.2-x86_64/tpm/tpm_structures.h  2005-08-15 
00:58:57.000000000 -0700
-+++ vtpm/tpm/tpm_structures.h  2006-05-17 09:31:11.000000000 -0700
+diff -uprN orig/tpm_emulator-0.3-x86_64/tpm/tpm_structures.h 
vtpm/tpm/tpm_structures.h
+--- orig/tpm_emulator-0.3-x86_64/tpm/tpm_structures.h  2006-01-10 
04:21:45.000000000 -0800
++++ vtpm/tpm/tpm_structures.h  2006-05-30 12:23:26.000000000 -0700
 @@ -1,6 +1,7 @@
  /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
   * Copyright (C) 2004 Mario Strasser <mast@xxxxxxx>,
@@ -1103,9 +1271,9 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
  #include "crypto/rsa.h"
  
  /*
-diff -uprN orig/tpm_emulator-0.2-x86_64/tpm/tpm_testing.c 
vtpm/tpm/tpm_testing.c
---- orig/tpm_emulator-0.2-x86_64/tpm/tpm_testing.c     2005-08-15 
00:58:57.000000000 -0700
-+++ vtpm/tpm/tpm_testing.c     2006-05-17 09:31:11.000000000 -0700
+diff -uprN orig/tpm_emulator-0.3-x86_64/tpm/tpm_testing.c 
vtpm/tpm/tpm_testing.c
+--- orig/tpm_emulator-0.3-x86_64/tpm/tpm_testing.c     2006-01-10 
04:21:45.000000000 -0800
++++ vtpm/tpm/tpm_testing.c     2006-05-30 12:23:26.000000000 -0700
 @@ -1,6 +1,7 @@
  /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
   * Copyright (C) 2004 Mario Strasser <mast@xxxxxxx>,
@@ -1221,9 +1389,9 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
    rsa_private_key_t priv_key;
    rsa_public_key_t pub_key;
  
-diff -uprN orig/tpm_emulator-0.2-x86_64/tpm/tpm_ticks.c vtpm/tpm/tpm_ticks.c
---- orig/tpm_emulator-0.2-x86_64/tpm/tpm_ticks.c       2005-08-15 
00:58:57.000000000 -0700
-+++ vtpm/tpm/tpm_ticks.c       2006-05-17 09:31:11.000000000 -0700
+diff -uprN orig/tpm_emulator-0.3-x86_64/tpm/tpm_ticks.c vtpm/tpm/tpm_ticks.c
+--- orig/tpm_emulator-0.3-x86_64/tpm/tpm_ticks.c       2006-01-10 
04:21:45.000000000 -0800
++++ vtpm/tpm/tpm_ticks.c       2006-05-30 12:23:26.000000000 -0700
 @@ -1,6 +1,7 @@
  /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
   * Copyright (C) 2004 Mario Strasser <mast@xxxxxxx>,
@@ -1306,9 +1474,69 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
  }
    
  
-diff -uprN orig/tpm_emulator-0.2-x86_64/tpmd.c vtpm/tpmd.c
---- orig/tpm_emulator-0.2-x86_64/tpmd.c        1969-12-31 16:00:00.000000000 
-0800
-+++ vtpm/tpmd.c        2006-05-17 09:31:11.000000000 -0700
+diff -uprN orig/tpm_emulator-0.3-x86_64/tpm/tpm_transport.c 
vtpm/tpm/tpm_transport.c
+--- orig/tpm_emulator-0.3-x86_64/tpm/tpm_transport.c   2006-01-10 
04:21:45.000000000 -0800
++++ vtpm/tpm/tpm_transport.c   2006-05-30 12:23:26.000000000 -0700
+@@ -59,7 +59,7 @@ static int decrypt_transport_auth(TPM_KE
+ static void transport_log_in(TPM_COMMAND_CODE ordinal, BYTE parameters[20],
+                              BYTE pubKeyHash[20], TPM_DIGEST *transDigest)
+ {
+-  UINT32 tag = cpu_to_be32(TPM_TAG_TRANSPORT_LOG_IN);
++  UINT32 tag = CPU_TO_BE32(TPM_TAG_TRANSPORT_LOG_IN);
+   BYTE *ptr, buf[sizeof_TPM_TRANSPORT_LOG_IN(x)];
+   UINT32 len = sizeof(buf);
+   sha1_ctx_t sha1;
+@@ -76,7 +76,7 @@ static void transport_log_in(TPM_COMMAND
+ static void transport_log_out(TPM_CURRENT_TICKS *currentTicks, BYTE 
parameters[20],
+                               TPM_MODIFIER_INDICATOR locality, TPM_DIGEST 
*transDigest)
+ {
+-  UINT32 tag = cpu_to_be32(TPM_TAG_TRANSPORT_LOG_OUT);
++  UINT32 tag = CPU_TO_BE32(TPM_TAG_TRANSPORT_LOG_OUT);
+   BYTE *ptr, buf[sizeof_TPM_TRANSPORT_LOG_OUT(x)];
+   UINT32 len = sizeof(buf);
+   sha1_ctx_t sha1;
+@@ -191,7 +191,7 @@ static void decrypt_wrapped_command(BYTE
+     sha1_update(&sha1, auth->nonceOdd.nonce, sizeof(auth->nonceOdd.nonce));
+     sha1_update(&sha1, "in", 2);
+     sha1_update(&sha1, secret, sizeof(TPM_SECRET));
+-    j = cpu_to_be32(i);
++    j = CPU_TO_BE32(i);
+     sha1_update(&sha1, (BYTE*)&j, 4);
+     sha1_final(&sha1, mask);
+     for (j = 0; j < sizeof(mask) && buf_len > 0; j++) { 
+@@ -213,7 +213,7 @@ static void encrypt_wrapped_command(BYTE
+     sha1_update(&sha1, auth->nonceOdd.nonce, sizeof(auth->nonceOdd.nonce));
+     sha1_update(&sha1, "out", 3);
+     sha1_update(&sha1, secret, sizeof(TPM_SECRET));
+-    j = cpu_to_be32(i);
++    j = CPU_TO_BE32(i);
+     sha1_update(&sha1, (BYTE*)&j, 4);
+     sha1_final(&sha1, mask);
+     for (j = 0; j < sizeof(mask) && buf_len > 0; j++) { 
+@@ -253,9 +253,9 @@ TPM_RESULT TPM_ExecuteTransport(UINT32 i
+   /* verify authorization */
+   tpm_compute_in_param_digest(&req);
+   sha1_init(&sha1);
+-  res = cpu_to_be32(TPM_ORD_ExecuteTransport);
++  res = CPU_TO_BE32(TPM_ORD_ExecuteTransport);
+   sha1_update(&sha1, (BYTE*)&res, 4);
+-  res = cpu_to_be32(inWrappedCmdSize);
++  res = CPU_TO_BE32(inWrappedCmdSize);
+   sha1_update(&sha1, (BYTE*)&res, 4);
+   sha1_update(&sha1, req.auth1.digest, sizeof(req.auth1.digest));
+   sha1_final(&sha1, auth1->digest);
+@@ -357,7 +357,7 @@ TPM_RESULT TPM_ReleaseTransportSigned(TP
+   /* setup a TPM_SIGN_INFO structure */
+   memcpy(&buf[0], "\x05\x00TRAN", 6);
+   memcpy(&buf[6], antiReplay->nonce, 20);
+-  *(UINT32*)&buf[26] = cpu_to_be32(20);
++  *(UINT32*)&buf[26] = CPU_TO_BE32(20);
+   memcpy(&buf[30], session->transInternal.transDigest.digest, 20);
+   /* sign info structure */ 
+   res = tpm_sign(key, auth1, TRUE, buf, sizeof(buf), signature, signSize);
+diff -uprN orig/tpm_emulator-0.3-x86_64/tpmd.c vtpm/tpmd.c
+--- orig/tpm_emulator-0.3-x86_64/tpmd.c        1969-12-31 16:00:00.000000000 
-0800
++++ vtpm/tpmd.c        2006-05-30 12:23:26.000000000 -0700
 @@ -0,0 +1,207 @@
 +/* Software-Based Trusted Platform Module (TPM) Emulator for Linux
 + * Copyright (C) 2005 INTEL Corp
diff -r 3be4c8288737 -r acabf4bdec4f xen/arch/x86/domain.c
--- a/xen/arch/x86/domain.c     Wed May 31 11:30:07 2006 -0600
+++ b/xen/arch/x86/domain.c     Wed May 31 13:05:21 2006 -0600
@@ -146,6 +146,8 @@ struct vcpu *alloc_vcpu_struct(struct do
     v->arch.guest_vl4table = __linear_l4_table;
 #endif
 
+    pae_l3_cache_init(&v->arch.pae_l3_cache);
+
     return v;
 }
 
diff -r 3be4c8288737 -r acabf4bdec4f xen/arch/x86/hvm/io.c
--- a/xen/arch/x86/hvm/io.c     Wed May 31 11:30:07 2006 -0600
+++ b/xen/arch/x86/hvm/io.c     Wed May 31 13:05:21 2006 -0600
@@ -648,6 +648,16 @@ static void hvm_mmio_assist(struct vcpu 
             regs->eflags &= ~X86_EFLAGS_CF;
 
         break;
+
+    case INSTR_XCHG:
+       if (src & REGISTER) {
+               index = operand_index(src);
+               set_reg_value(size, index, 0, regs, p->u.data);
+       } else {
+               index = operand_index(dst);
+               set_reg_value(size, index, 0, regs, p->u.data);
+       }
+       break;
     }
 
     hvm_load_cpu_guest_regs(v, regs);
diff -r 3be4c8288737 -r acabf4bdec4f xen/arch/x86/hvm/platform.c
--- a/xen/arch/x86/hvm/platform.c       Wed May 31 11:30:07 2006 -0600
+++ b/xen/arch/x86/hvm/platform.c       Wed May 31 13:05:21 2006 -0600
@@ -954,10 +954,26 @@ void handle_mmio(unsigned long va, unsig
         mmio_opp->instr = mmio_inst.instr;
         mmio_opp->operand[0] = mmio_inst.operand[0]; /* source */
         mmio_opp->operand[1] = mmio_inst.operand[1]; /* destination */
-
-        /* send the request and wait for the value */
-        send_mmio_req(IOREQ_TYPE_XCHG, gpa, 1,
-                      mmio_inst.op_size, 0, IOREQ_WRITE, 0);
+       if (mmio_inst.operand[0] & REGISTER) {
+               long value;
+               unsigned long operand = mmio_inst.operand[0];
+               value = get_reg_value(operand_size(operand), 
+                                     operand_index(operand), 0,
+                                     mmio_opp->inst_decoder_regs);
+               /* send the request and wait for the value */
+               send_mmio_req(IOREQ_TYPE_XCHG, gpa, 1,
+                      mmio_inst.op_size, value, IOREQ_WRITE, 0);
+       } else {
+               /* the destination is a register */
+               long value;
+               unsigned long operand = mmio_inst.operand[1];
+               value = get_reg_value(operand_size(operand), 
+                                     operand_index(operand), 0,
+                                     mmio_opp->inst_decoder_regs);
+               /* send the request and wait for the value */
+               send_mmio_req(IOREQ_TYPE_XCHG, gpa, 1,
+                      mmio_inst.op_size, value, IOREQ_WRITE, 0);
+       }
         break;
 
     default:
diff -r 3be4c8288737 -r acabf4bdec4f xen/arch/x86/hvm/svm/svm.c
--- a/xen/arch/x86/hvm/svm/svm.c        Wed May 31 11:30:07 2006 -0600
+++ b/xen/arch/x86/hvm/svm/svm.c        Wed May 31 13:05:21 2006 -0600
@@ -51,9 +51,6 @@
 
 #define SVM_EXTRA_DEBUG
 
-/* Useful define */
-#define MAX_INST_SIZE  15
-
 #define set_segment_register(name, value)  \
        __asm__ __volatile__ ( "movw %%ax ,%%" STR(name) "" : : "a" (value) )
 
@@ -74,6 +71,9 @@ void svm_dump_regs(const char *from, str
 void svm_dump_regs(const char *from, struct cpu_user_regs *regs);
 
 static void svm_relinquish_guest_resources(struct domain *d);
+static int svm_do_vmmcall_reset_to_realmode(struct vcpu *v,
+        struct cpu_user_regs *regs);
+
 
 
 extern void set_hsa_to_guest( struct arch_svm_struct *arch_svm );
@@ -438,6 +438,42 @@ unsigned long svm_get_ctrl_reg(struct vc
     return 0;                   /* dummy */
 }
 
+
+/* SVM-specific intitialization code for VCPU application processors */
+void svm_init_ap_context(struct vcpu_guest_context *ctxt, 
+        int vcpuid, int trampoline_vector)
+{
+    int i;
+    struct vcpu *v, *bsp = current;
+    struct domain *d = bsp->domain;
+    cpu_user_regs_t *regs;;
+
+  
+    if ((v = d->vcpu[vcpuid]) == NULL)
+    {
+        printk("vcpuid %d is invalid!  good-bye.\n", vcpuid);
+        domain_crash_synchronous();
+    }
+    regs = &v->arch.guest_context.user_regs;
+
+    memset(ctxt, 0, sizeof(*ctxt));
+    for (i = 0; i < 256; ++i)
+    {
+        ctxt->trap_ctxt[i].vector = i;
+        ctxt->trap_ctxt[i].cs = FLAT_KERNEL_CS;
+    }
+
+
+    /*
+     * We execute the trampoline code in real mode. The trampoline vector
+     * passed to us is page alligned and is the physicall frame number for
+     * the code. We will execute this code in real mode. 
+     */
+    ctxt->user_regs.eip = 0x0;
+    ctxt->user_regs.cs = (trampoline_vector << 8); 
+    ctxt->flags = VGCF_HVM_GUEST;
+}
+
 int start_svm(void)
 {
     u32 eax, ecx, edx;
@@ -484,6 +520,7 @@ int start_svm(void)
     hvm_funcs.paging_enabled = svm_paging_enabled;
     hvm_funcs.instruction_length = svm_instruction_length;
     hvm_funcs.get_guest_ctrl_reg = svm_get_ctrl_reg;
+    hvm_funcs.init_ap_context = svm_init_ap_context;
 
     hvm_enabled = 1;    
 
@@ -660,6 +697,20 @@ static void arch_svm_do_launch(struct vc
     if (svm_dbg_on)
         svm_dump_host_regs(__func__);
 #endif
+    if (v->vcpu_id != 0) 
+    {
+       u16     cs_sel = regs->cs;
+       /*
+        * This is the launch of an AP; set state so that we begin executing
+        * the trampoline code in real-mode.
+        */
+       svm_do_vmmcall_reset_to_realmode(v, regs);      
+       /* Adjust the state to execute the trampoline code.*/
+       v->arch.hvm_svm.vmcb->rip = 0;
+       v->arch.hvm_svm.vmcb->cs.sel= cs_sel;
+       v->arch.hvm_svm.vmcb->cs.base = (cs_sel << 4);
+    }
+       
     reset_stack_and_jump(svm_asm_do_launch);
 }
 
@@ -896,8 +947,10 @@ static void svm_do_general_protection_fa
     svm_inject_exception(v, TRAP_gp_fault, 1, error_code);
 }
 
-/* Reserved bits: [31:14], [12:1] */
-#define SVM_VCPU_CPUID_L1_RESERVED 0xffffdffe
+/* Reserved bits ECX: [31:14], [12:4], [2:1]*/
+#define SVM_VCPU_CPUID_L1_ECX_RESERVED 0xffffdff6
+/* Reserved bits EDX: [31:29], [27], [22:20], [18], [10] */
+#define SVM_VCPU_CPUID_L1_EDX_RESERVED 0xe8740400
 
 static void svm_vmexit_do_cpuid(struct vmcb_struct *vmcb, unsigned long input, 
         struct cpu_user_regs *regs) 
@@ -920,20 +973,17 @@ static void svm_vmexit_do_cpuid(struct v
 
     cpuid(input, &eax, &ebx, &ecx, &edx);
 
-    if (input == 1)
+    if (input == 0x00000001)
     {
         if ( !hvm_apic_support(v->domain) ||
                 !vlapic_global_enabled((VLAPIC(v))) )
         {
-            clear_bit(X86_FEATURE_APIC, &edx);
-            /* Since the apic is disabled, avoid any confusion about SMP cpus 
being available */
-            clear_bit(X86_FEATURE_HT, &edx);  /* clear the hyperthread bit */
-            ebx &= 0xFF00FFFF;  /* set the logical processor count to 1 */
-            ebx |= 0x00010000;
-        }
-           
+            /* Since the apic is disabled, avoid any confusion 
+              about SMP cpus being available */
+           clear_bit(X86_FEATURE_APIC, &edx);
+        }
+
 #if CONFIG_PAGING_LEVELS < 3
-        clear_bit(X86_FEATURE_NX, &edx);
         clear_bit(X86_FEATURE_PAE, &edx);
         clear_bit(X86_FEATURE_PSE, &edx);
         clear_bit(X86_FEATURE_PSE36, &edx);
@@ -942,24 +992,90 @@ static void svm_vmexit_do_cpuid(struct v
         {
             if ( !v->domain->arch.hvm_domain.pae_enabled )
             {
-               clear_bit(X86_FEATURE_PAE, &edx);
-               clear_bit(X86_FEATURE_NX, &edx);
+               clear_bit(X86_FEATURE_PAE, &edx);
             }
             clear_bit(X86_FEATURE_PSE, &edx);
             clear_bit(X86_FEATURE_PSE36, &edx);
         }
 #endif 
         /* Clear out reserved bits. */
-        ecx &= ~SVM_VCPU_CPUID_L1_RESERVED; /* mask off reserved bits */
+        ecx &= ~SVM_VCPU_CPUID_L1_ECX_RESERVED;
+        edx &= ~SVM_VCPU_CPUID_L1_EDX_RESERVED;
+
         clear_bit(X86_FEATURE_MWAIT & 31, &ecx);
-    }
+
+       /* Guest should only see one logical processor.
+        * See details on page 23 of AMD CPUID Specification. 
+       */
+       clear_bit(X86_FEATURE_HT, &edx);  /* clear the hyperthread bit */
+       ebx &= 0xFF00FFFF;  /* clear the logical processor count when HTT=0 */
+       ebx |= 0x00010000;  /* set to 1 just for precaution */
+    }
+    else if ( ( input > 0x00000005 ) && ( input < 0x80000000 ) )
+    {
+       eax = ebx = ecx = edx = 0x0;
+    }
+    else if ( input == 0x80000001 )
+    {
+       /* We duplicate some CPUID_00000001 code because many bits of 
+          CPUID_80000001_EDX overlaps with CPUID_00000001_EDX. */
+
+        if ( !hvm_apic_support(v->domain) ||
+            !vlapic_global_enabled((VLAPIC(v))) )
+        {
+            /* Since the apic is disabled, avoid any confusion 
+              about SMP cpus being available */
+           clear_bit(X86_FEATURE_APIC, &edx);
+        }
+
+       /* Clear the Cmp_Legacy bit 
+        * This bit is supposed to be zero when HTT = 0.
+        * See details on page 23 of AMD CPUID Specification. 
+       */
+       clear_bit(X86_FEATURE_CMP_LEGACY & 31, &ecx);
+
 #ifdef __i386__
-    else if ( input == 0x80000001 )
-    {
         /* Mask feature for Intel ia32e or AMD long mode. */
+        clear_bit(X86_FEATURE_LAHF_LM & 31, &ecx);
+
         clear_bit(X86_FEATURE_LM & 31, &edx);
-    }
+        clear_bit(X86_FEATURE_SYSCALL & 31, &edx);
 #endif
+
+#if CONFIG_PAGING_LEVELS < 3
+       clear_bit(X86_FEATURE_NX & 31, &edx);
+        clear_bit(X86_FEATURE_PAE, &edx);
+        clear_bit(X86_FEATURE_PSE, &edx);
+        clear_bit(X86_FEATURE_PSE36, &edx);
+#else
+        if ( v->domain->arch.ops->guest_paging_levels == PAGING_L2 )
+        {
+            if ( !v->domain->arch.hvm_domain.pae_enabled )
+            {
+               clear_bit(X86_FEATURE_NX & 31, &edx);
+               clear_bit(X86_FEATURE_PAE, &edx);
+            }
+            clear_bit(X86_FEATURE_PSE, &edx);
+            clear_bit(X86_FEATURE_PSE36, &edx);
+        }
+#endif 
+
+        /* Make SVM feature invisible to the guest. */
+        clear_bit(X86_FEATURE_SVME & 31, &ecx);
+       
+       /* So far, we do not support 3DNow for the guest. */
+       clear_bit(X86_FEATURE_3DNOW & 31, &edx);
+       clear_bit(X86_FEATURE_3DNOWEXT & 31, &edx);
+    }
+    else if ( ( input == 0x80000007 ) || ( input == 0x8000000A  ) )
+    {
+       /* Mask out features of power management and SVM extension. */
+       eax = ebx = ecx = edx = 0;
+    }
+    else if ( input == 0x80000008 )
+    {
+       ecx &= 0xFFFFFF00; /* Make sure Number of CPU core is 1 when HTT=0 */
+    }
 
     regs->eax = (unsigned long)eax;
     regs->ebx = (unsigned long)ebx;
@@ -2036,7 +2152,7 @@ void svm_handle_invlpg(const short invlp
 void svm_handle_invlpg(const short invlpga, struct cpu_user_regs *regs)
 {
     struct vcpu *v = current;
-    u8 opcode[MAX_INST_SIZE], prefix, length = MAX_INST_SIZE;
+    u8 opcode[MAX_INST_LEN], prefix, length = MAX_INST_LEN;
     unsigned long g_vaddr;
     int inst_len;
     struct vmcb_struct *vmcb = v->arch.hvm_svm.vmcb;
diff -r 3be4c8288737 -r acabf4bdec4f xen/arch/x86/mm.c
--- a/xen/arch/x86/mm.c Wed May 31 11:30:07 2006 -0600
+++ b/xen/arch/x86/mm.c Wed May 31 13:05:21 2006 -0600
@@ -260,38 +260,85 @@ void share_xen_page_with_privileged_gues
     share_xen_page_with_guest(page, dom_xen, readonly);
 }
 
+#if defined(CONFIG_X86_PAE)
+
+#ifdef NDEBUG
+/* Only PDPTs above 4GB boundary need to be shadowed in low memory. */
+#define l3tab_needs_shadow(mfn) (mfn >= 0x100000)
+#else
+/*
+ * In debug builds we aggressively shadow PDPTs to exercise code paths.
+ * We cannot safely shadow the idle page table, nor shadow-mode page tables
+ * (detected by lack of an owning domain). Always shadow PDPTs above 4GB.
+ */
+#define l3tab_needs_shadow(mfn)                         \
+    ((((mfn << PAGE_SHIFT) != __pa(idle_pg_table)) &&   \
+      (page_get_owner(mfn_to_page(mfn)) != NULL)) ||    \
+     (mfn >= 0x100000))
+#endif
+
+static l1_pgentry_t *fix_pae_highmem_pl1e;
+
+/* Cache the address of PAE high-memory fixmap page tables. */
+static int __init cache_pae_fixmap_address(void)
+{
+    unsigned long fixmap_base = fix_to_virt(FIX_PAE_HIGHMEM_0);
+    l2_pgentry_t *pl2e = virt_to_xen_l2e(fixmap_base);
+    fix_pae_highmem_pl1e = l2e_to_l1e(*pl2e) + l1_table_offset(fixmap_base);
+    return 0;
+}
+__initcall(cache_pae_fixmap_address);
+
 static void __write_ptbase(unsigned long mfn)
 {
-#ifdef CONFIG_X86_PAE
-    if ( mfn >= 0x100000 )
-    {
-        l3_pgentry_t *highmem_l3tab, *lowmem_l3tab;
-        struct vcpu *v = current;
-        unsigned long flags;
-
-        /* Protects against re-entry and against __pae_flush_pgd(). */
-        local_irq_save(flags);
-
-        /* Pick an unused low-memory L3 cache slot. */
-        v->arch.lowmem_l3tab_inuse ^= 1;
-        lowmem_l3tab = v->arch.lowmem_l3tab[v->arch.lowmem_l3tab_inuse];
-        v->arch.lowmem_l3tab_high_mfn[v->arch.lowmem_l3tab_inuse] = mfn;
-
-        /* Map the guest L3 table and copy to the chosen low-memory cache. */
-        highmem_l3tab = map_domain_page(mfn);
-        memcpy(lowmem_l3tab, highmem_l3tab, sizeof(v->arch.lowmem_l3tab));
-        unmap_domain_page(highmem_l3tab);
-
-        /* Install the low-memory L3 table in CR3. */
-        write_cr3(__pa(lowmem_l3tab));
-
-        local_irq_restore(flags);
+    l3_pgentry_t *highmem_l3tab, *lowmem_l3tab;
+    struct pae_l3_cache *cache = &current->arch.pae_l3_cache;
+    unsigned int cpu = smp_processor_id();
+
+    /* Fast path 1: does this mfn need a shadow at all? */
+    if ( !l3tab_needs_shadow(mfn) )
+    {
+        write_cr3(mfn << PAGE_SHIFT);
         return;
     }
-#endif
-
+
+    /* Caching logic is not interrupt safe. */
+    ASSERT(!in_irq());
+
+    /* Fast path 2: is this mfn already cached? */
+    if ( cache->high_mfn == mfn )
+    {
+        write_cr3(__pa(cache->table[cache->inuse_idx]));
+        return;
+    }
+
+    /* Protects against pae_flush_pgd(). */
+    spin_lock(&cache->lock);
+
+    cache->inuse_idx ^= 1;
+    cache->high_mfn   = mfn;
+
+    /* Map the guest L3 table and copy to the chosen low-memory cache. */
+    *(fix_pae_highmem_pl1e - cpu) = l1e_from_pfn(mfn, __PAGE_HYPERVISOR);
+    highmem_l3tab = (l3_pgentry_t *)fix_to_virt(FIX_PAE_HIGHMEM_0 + cpu);
+    lowmem_l3tab  = cache->table[cache->inuse_idx];
+    memcpy(lowmem_l3tab, highmem_l3tab, sizeof(cache->table[0]));
+    *(fix_pae_highmem_pl1e - cpu) = l1e_empty();
+
+    /* Install the low-memory L3 table in CR3. */
+    write_cr3(__pa(lowmem_l3tab));
+
+    spin_unlock(&cache->lock);
+}
+
+#else /* !CONFIG_X86_PAE */
+
+static void __write_ptbase(unsigned long mfn)
+{
     write_cr3(mfn << PAGE_SHIFT);
 }
+
+#endif /* !CONFIG_X86_PAE */
 
 void write_ptbase(struct vcpu *v)
 {
@@ -804,48 +851,39 @@ static int create_pae_xen_mappings(l3_pg
     return 1;
 }
 
-struct pae_flush_pgd {
-    unsigned long l3tab_mfn;
-    unsigned int  l3tab_idx;
-    l3_pgentry_t  nl3e;
-};
-
-static void __pae_flush_pgd(void *data)
-{
-    struct pae_flush_pgd *args = data;
-    struct vcpu *v = this_cpu(curr_vcpu);
-    int i = v->arch.lowmem_l3tab_inuse;
-    intpte_t _ol3e, _nl3e, _pl3e;
-    l3_pgentry_t *l3tab_ptr;
-
-    ASSERT(!local_irq_is_enabled());
-
-    if ( v->arch.lowmem_l3tab_high_mfn[i] != args->l3tab_mfn )
-        return;
-
-    l3tab_ptr = &v->arch.lowmem_l3tab[i][args->l3tab_idx];
-
-    _ol3e = l3e_get_intpte(*l3tab_ptr);
-    _nl3e = l3e_get_intpte(args->nl3e);
-    _pl3e = cmpxchg((intpte_t *)l3tab_ptr, _ol3e, _nl3e);
-    BUG_ON(_pl3e != _ol3e);
-}
-
 /* Flush a pgdir update into low-memory caches. */
 static void pae_flush_pgd(
     unsigned long mfn, unsigned int idx, l3_pgentry_t nl3e)
 {
     struct domain *d = page_get_owner(mfn_to_page(mfn));
-    struct pae_flush_pgd args = {
-        .l3tab_mfn = mfn,
-        .l3tab_idx = idx,
-        .nl3e      = nl3e };
+    struct vcpu   *v;
+    intpte_t       _ol3e, _nl3e, _pl3e;
+    l3_pgentry_t  *l3tab_ptr;
+    struct pae_l3_cache *cache;
 
     /* If below 4GB then the pgdir is not shadowed in low memory. */
-    if ( mfn < 0x100000 )
+    if ( !l3tab_needs_shadow(mfn) )
         return;
 
-    on_selected_cpus(d->domain_dirty_cpumask, __pae_flush_pgd, &args, 1, 1);
+    for_each_vcpu ( d, v )
+    {
+        cache = &v->arch.pae_l3_cache;
+
+        spin_lock(&cache->lock);
+
+        if ( cache->high_mfn == mfn )
+        {
+            l3tab_ptr = &cache->table[cache->inuse_idx][idx];
+            _ol3e = l3e_get_intpte(*l3tab_ptr);
+            _nl3e = l3e_get_intpte(nl3e);
+            _pl3e = cmpxchg((intpte_t *)l3tab_ptr, _ol3e, _nl3e);
+            BUG_ON(_pl3e != _ol3e);
+        }
+
+        spin_unlock(&cache->lock);
+    }
+
+    flush_tlb_mask(d->domain_dirty_cpumask);
 }
 
 static inline int l1_backptr(
@@ -1567,12 +1605,18 @@ int get_page_type(struct page_info *page
             {
                 if ( unlikely((x & PGT_type_mask) != (type & PGT_type_mask) ) )
                 {
-                    if ( current->domain == page_get_owner(page) )
+                    if ( (current->domain == page_get_owner(page)) &&
+                         ((x & PGT_type_mask) == PGT_writable_page) )
                     {
                         /*
                          * This ensures functions like set_gdt() see up-to-date
                          * type info without needing to clean up writable p.t.
-                         * state on the fast path.
+                         * state on the fast path. We take this path only
+                         * when the current type is writable because:
+                         *  1. It's the only type that this path can decrement.
+                         *  2. If we take this path more liberally then we can
+                         *     enter a recursive loop via get_page_from_l1e()
+                         *     during pagetable revalidation.
                          */
                         LOCK_BIGLOCK(current->domain);
                         cleanup_writable_pagetable(current->domain);
@@ -3708,11 +3752,10 @@ int map_pages_to_xen(
 }
 
 void __set_fixmap(
-    enum fixed_addresses idx, unsigned long p, unsigned long flags)
-{
-    if ( unlikely(idx >= __end_of_fixed_addresses) )
-        BUG();
-    map_pages_to_xen(fix_to_virt(idx), p >> PAGE_SHIFT, 1, flags);
+    enum fixed_addresses idx, unsigned long mfn, unsigned long flags)
+{
+    BUG_ON(idx >= __end_of_fixed_addresses);
+    map_pages_to_xen(fix_to_virt(idx), mfn, 1, flags);
 }
 
 #ifdef MEMORY_GUARD
diff -r 3be4c8288737 -r acabf4bdec4f xen/arch/x86/shadow.c
--- a/xen/arch/x86/shadow.c     Wed May 31 11:30:07 2006 -0600
+++ b/xen/arch/x86/shadow.c     Wed May 31 13:05:21 2006 -0600
@@ -1724,7 +1724,8 @@ static int resync_all(struct domain *d, 
                         unshadow_l1 = 1;
                     else {
                         need_flush |= error;
-                        set_guest_back_ptr(d, *sl1e_p, smfn, i);
+                        if ( l1e_get_flags(*sl1e_p) & _PAGE_PRESENT )
+                            set_guest_back_ptr(d, *sl1e_p, smfn, i);
                     }
                     // can't update snapshots of linear page tables -- they
                     // are used multiple times...
diff -r 3be4c8288737 -r acabf4bdec4f xen/arch/x86/shadow32.c
--- a/xen/arch/x86/shadow32.c   Wed May 31 11:30:07 2006 -0600
+++ b/xen/arch/x86/shadow32.c   Wed May 31 13:05:21 2006 -0600
@@ -2691,7 +2691,8 @@ static int resync_all(struct domain *d, 
                         unshadow_l1 = 1;
                     else {
                         need_flush |= error;
-                        set_guest_back_ptr(d, shadow1[i], smfn, i);
+                        if ( l1e_get_flags(shadow1[i]) & _PAGE_PRESENT )
+                            set_guest_back_ptr(d, shadow1[i], smfn, i);
                     }
 
                     // can't update snapshots of linear page tables -- they
diff -r 3be4c8288737 -r acabf4bdec4f xen/include/asm-x86/domain.h
--- a/xen/include/asm-x86/domain.h      Wed May 31 11:30:07 2006 -0600
+++ b/xen/include/asm-x86/domain.h      Wed May 31 13:05:21 2006 -0600
@@ -114,23 +114,32 @@ struct arch_domain
     unsigned long first_reserved_pfn;
 } __cacheline_aligned;
 
-struct arch_vcpu
-{
-    /* Needs 16-byte aligment for FXSAVE/FXRSTOR. */
-    struct vcpu_guest_context guest_context
-    __attribute__((__aligned__(16)));
-
 #ifdef CONFIG_X86_PAE
+struct pae_l3_cache {
     /*
      * Two low-memory (<4GB) PAE L3 tables, used as fallback when the guest
      * supplies a >=4GB PAE L3 table. We need two because we cannot set up
      * an L3 table while we are currently running on it (without using
      * expensive atomic 64-bit operations).
      */
-    l3_pgentry_t  lowmem_l3tab[2][4] __attribute__((__aligned__(32)));
-    unsigned long lowmem_l3tab_high_mfn[2]; /* The >=4GB MFN being shadowed. */
-    unsigned int  lowmem_l3tab_inuse;       /* Which lowmem_l3tab is in use? */
-#endif
+    l3_pgentry_t  table[2][4] __attribute__((__aligned__(32)));
+    unsigned long high_mfn;  /* The >=4GB MFN being shadowed. */
+    unsigned int  inuse_idx; /* Which of the two cache slots is in use? */
+    spinlock_t    lock;
+};
+#define pae_l3_cache_init(c) spin_lock_init(&(c)->lock)
+#else /* !CONFIG_X86_PAE */
+struct pae_l3_cache { };
+#define pae_l3_cache_init(c) ((void)0)
+#endif
+
+struct arch_vcpu
+{
+    /* Needs 16-byte aligment for FXSAVE/FXRSTOR. */
+    struct vcpu_guest_context guest_context
+    __attribute__((__aligned__(16)));
+
+    struct pae_l3_cache pae_l3_cache;
 
     unsigned long      flags; /* TF_ */
 
diff -r 3be4c8288737 -r acabf4bdec4f xen/include/asm-x86/fixmap.h
--- a/xen/include/asm-x86/fixmap.h      Wed May 31 11:30:07 2006 -0600
+++ b/xen/include/asm-x86/fixmap.h      Wed May 31 13:05:21 2006 -0600
@@ -25,6 +25,10 @@
  * from the end of virtual memory backwards.
  */
 enum fixed_addresses {
+#ifdef CONFIG_X86_PAE
+    FIX_PAE_HIGHMEM_0,
+    FIX_PAE_HIGHMEM_END = FIX_PAE_HIGHMEM_0 + NR_CPUS-1,
+#endif
     FIX_APIC_BASE,
     FIX_IO_APIC_BASE_0,
     FIX_IO_APIC_BASE_END = FIX_IO_APIC_BASE_0 + MAX_IO_APICS-1,
@@ -40,13 +44,13 @@ enum fixed_addresses {
 #define FIXADDR_START (FIXADDR_TOP - FIXADDR_SIZE)
 
 extern void __set_fixmap(
-    enum fixed_addresses idx, unsigned long p, unsigned long flags);
+    enum fixed_addresses idx, unsigned long mfn, unsigned long flags);
 
 #define set_fixmap(idx, phys) \
-    __set_fixmap(idx, phys, PAGE_HYPERVISOR)
+    __set_fixmap(idx, (phys)>>PAGE_SHIFT, PAGE_HYPERVISOR)
 
 #define set_fixmap_nocache(idx, phys) \
-    __set_fixmap(idx, phys, PAGE_HYPERVISOR_NOCACHE)
+    __set_fixmap(idx, (phys)>>PAGE_SHIFT, PAGE_HYPERVISOR_NOCACHE)
 
 #define __fix_to_virt(x) (FIXADDR_TOP - ((x) << PAGE_SHIFT))
 #define __virt_to_fix(x) ((FIXADDR_TOP - ((x)&PAGE_MASK)) >> PAGE_SHIFT)
diff -r 3be4c8288737 -r acabf4bdec4f xen/include/asm-x86/shadow.h
--- a/xen/include/asm-x86/shadow.h      Wed May 31 11:30:07 2006 -0600
+++ b/xen/include/asm-x86/shadow.h      Wed May 31 13:05:21 2006 -0600
@@ -762,10 +762,16 @@ static inline void set_guest_back_ptr(
         unsigned long gmfn;
 
         ASSERT(shadow_lock_is_acquired(d));
+        ASSERT( smfn );
         gmfn = l1e_get_pfn(spte);
-        mfn_to_page(gmfn)->tlbflush_timestamp = smfn;
-        mfn_to_page(gmfn)->u.inuse.type_info &= ~PGT_va_mask;
-        mfn_to_page(gmfn)->u.inuse.type_info |= (unsigned long) index << 
PGT_va_shift;
+        ASSERT( gmfn );
+        if ( l1e_get_flags(spte) & _PAGE_RW )
+        {
+            mfn_to_page(gmfn)->tlbflush_timestamp = smfn;
+            mfn_to_page(gmfn)->u.inuse.type_info &= ~PGT_va_mask;
+            mfn_to_page(gmfn)->u.inuse.type_info |= 
+                (unsigned long) index << PGT_va_shift;
+        }
     }
 }
 
diff -r 3be4c8288737 -r acabf4bdec4f xen/include/public/sched_ctl.h
--- a/xen/include/public/sched_ctl.h    Wed May 31 11:30:07 2006 -0600
+++ b/xen/include/public/sched_ctl.h    Wed May 31 13:05:21 2006 -0600
@@ -49,7 +49,7 @@ struct sched_adjdom_cmd {
             uint32_t extratime;
             uint32_t weight;
         } sedf;
-        struct csched_domain {
+        struct sched_credit_adjdom {
             uint16_t weight;
             uint16_t cap;
         } credit;
diff -r 3be4c8288737 -r acabf4bdec4f xen/include/xen/perfc.h
--- a/xen/include/xen/perfc.h   Wed May 31 11:30:07 2006 -0600
+++ b/xen/include/xen/perfc.h   Wed May 31 13:05:21 2006 -0600
@@ -56,10 +56,8 @@ extern struct perfcounter perfcounters;
 #define perfc_value(x)    atomic_read(&perfcounters.x[0])
 #define perfc_valuec(x)   atomic_read(&perfcounters.x[smp_processor_id()])
 #define perfc_valuea(x,y)                                               \
-    do {                                                                \
-        if ( (y) < (sizeof(perfcounters.x) / sizeof(*perfcounters.x)) ) \
-            atomic_read(&perfcounters.x[y]);                            \
-    } while ( 0 )
+    ( (y) < (sizeof(perfcounters.x) / sizeof(*perfcounters.x)) ?       \
+       atomic_read(&perfcounters.x[y]) : 0 )
 #define perfc_set(x,v)    atomic_set(&perfcounters.x[0], v)
 #define perfc_setc(x,v)   atomic_set(&perfcounters.x[smp_processor_id()], v)
 #define perfc_seta(x,y,v)                                               \
diff -r 3be4c8288737 -r acabf4bdec4f xen/tools/Makefile
--- a/xen/tools/Makefile        Wed May 31 11:30:07 2006 -0600
+++ b/xen/tools/Makefile        Wed May 31 13:05:21 2006 -0600
@@ -1,5 +1,6 @@
 
-include $(BASEDIR)/../Config.mk
+XEN_ROOT = $(BASEDIR)/..
+include $(XEN_ROOT)/Config.mk
 
 .PHONY: default
 default:
diff -r 3be4c8288737 -r acabf4bdec4f xen/tools/figlet/Makefile
--- a/xen/tools/figlet/Makefile Wed May 31 11:30:07 2006 -0600
+++ b/xen/tools/figlet/Makefile Wed May 31 13:05:21 2006 -0600
@@ -1,5 +1,6 @@
 
-include $(BASEDIR)/../Config.mk
+XEN_ROOT = $(BASEDIR)/..
+include $(XEN_ROOT)/Config.mk
 
 figlet: figlet.c
        $(HOSTCC) -o $@ $<
diff -r 3be4c8288737 -r acabf4bdec4f config/ia64.mk
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/config/ia64.mk    Wed May 31 13:05:21 2006 -0600
@@ -0,0 +1,4 @@
+CONFIG_IA64 := y
+CONFIG_IOEMU := y
+
+LIBDIR := lib
diff -r 3be4c8288737 -r acabf4bdec4f config/x86_32.mk
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/config/x86_32.mk  Wed May 31 13:05:21 2006 -0600
@@ -0,0 +1,9 @@
+CONFIG_X86 := y
+CONFIG_PLAN9 := y
+CONFIG_HVM := y
+CONFIG_MIGRATE := y
+CONFIG_IOEMU := y
+CONFIG_MBOOTPACK := y
+
+CFLAGS += -m32 -march=i686
+LIBDIR := lib
diff -r 3be4c8288737 -r acabf4bdec4f config/x86_64.mk
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/config/x86_64.mk  Wed May 31 13:05:21 2006 -0600
@@ -0,0 +1,9 @@
+CONFIG_X86 := y
+CONFIG_PLAN9 := y
+CONFIG_HVM := y
+CONFIG_MIGRATE := y
+CONFIG_IOEMU := y
+CONFIG_MBOOTPACK := y
+
+CFLAGS += -m64
+LIBDIR = lib64
diff -r 3be4c8288737 -r acabf4bdec4f tools/vtpm/tpm_emulator-0.3-x86_64.patch
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/vtpm/tpm_emulator-0.3-x86_64.patch  Wed May 31 13:05:21 2006 -0600
@@ -0,0 +1,484 @@
+diff -uprN tpm_emulator-0.3/crypto/gmp_kernel_wrapper.c 
tpm_emulator-0.3-x86_64/crypto/gmp_kernel_wrapper.c
+--- tpm_emulator-0.3/crypto/gmp_kernel_wrapper.c       2006-01-10 
04:21:45.000000000 -0800
++++ tpm_emulator-0.3-x86_64/crypto/gmp_kernel_wrapper.c        2006-05-26 
11:26:02.000000000 -0700
+@@ -79,7 +79,7 @@ void __attribute__ ((regparm(0))) *kerne
+ {
+   void *ret  = (void*)kmalloc(size, GFP_KERNEL);
+   if (!ret) panic(KERN_CRIT TPM_MODULE_NAME 
+-    "GMP: cannot allocate memory (size=%u)\n", size);
++    "GMP: cannot allocate memory (size=%Zu)\n", size);
+   return ret;
+ }
+ 
+@@ -88,7 +88,7 @@ void __attribute__ ((regparm(0))) *kerne
+ {
+   void *ret = (void*)kmalloc(new_size, GFP_KERNEL);
+   if (!ret) panic(KERN_CRIT TPM_MODULE_NAME "GMP: Cannot reallocate memory "
+-    "(old_size=%u new_size=%u)\n", old_size, new_size);
++    "(old_size=%Zu new_size=%Zu)\n", old_size, new_size);
+   memcpy(ret, oldptr, old_size);
+   kfree(oldptr);
+   return ret;
+diff -uprN tpm_emulator-0.3/linux_module.c 
tpm_emulator-0.3-x86_64/linux_module.c
+--- tpm_emulator-0.3/linux_module.c    2006-01-10 04:21:45.000000000 -0800
++++ tpm_emulator-0.3-x86_64/linux_module.c     2006-05-26 11:26:02.000000000 
-0700
+@@ -72,7 +72,7 @@ static int tpm_release(struct inode *ino
+ 
+ static ssize_t tpm_read(struct file *file, char *buf, size_t count, loff_t 
*ppos)
+ {
+-  debug("%s(%d)", __FUNCTION__, count);
++  debug("%s(%Zu)", __FUNCTION__, count);
+   down(&tpm_mutex);
+   if (tpm_response.data != NULL) {
+     count = min(count, (size_t)tpm_response.size - (size_t)*ppos);
+@@ -91,7 +91,7 @@ static ssize_t tpm_read(struct file *fil
+ 
+ static ssize_t tpm_write(struct file *file, const char *buf, size_t count, 
loff_t *ppos)
+ {
+-  debug("%s(%d)", __FUNCTION__, count);
++  debug("%s(%Zu)", __FUNCTION__, count);
+   down(&tpm_mutex);
+   *ppos = 0;
+   if (tpm_response.data != NULL) kfree(tpm_response.data);
+diff -uprN tpm_emulator-0.3/linux_module.h 
tpm_emulator-0.3-x86_64/linux_module.h
+--- tpm_emulator-0.3/linux_module.h    2006-01-10 04:21:45.000000000 -0800
++++ tpm_emulator-0.3-x86_64/linux_module.h     2006-05-26 11:26:02.000000000 
-0700
+@@ -28,8 +28,10 @@
+ 
+ /* module settings */
+ 
++#ifndef STR
+ #define STR(s) __STR__(s)
+ #define __STR__(s) #s
++#endif
+ #include "tpm_version.h"
+ 
+ #define TPM_DEVICE_MINOR      224
+diff -uprN tpm_emulator-0.3/Makefile tpm_emulator-0.3-x86_64/Makefile
+--- tpm_emulator-0.3/Makefile  2006-01-10 04:21:45.000000000 -0800
++++ tpm_emulator-0.3-x86_64/Makefile   2006-05-26 11:26:02.000000000 -0700
+@@ -7,6 +7,7 @@
+ KERNEL_RELEASE := $(shell uname -r)
+ KERNEL_BUILD   := /lib/modules/$(KERNEL_RELEASE)/build
+ MOD_SUBDIR     := misc
++COMPILE_ARCH    ?= $(shell uname -m | sed -e s/i.86/x86_32/)
+ 
+ # module settings
+ MODULE_NAME    := tpm_emulator
+@@ -17,8 +18,14 @@ VERSION_BUILD  := $(shell date +"%s")
+ # enable/disable DEBUG messages
+ EXTRA_CFLAGS   += -Wall -DDEBUG -g  
+ 
++ifeq ($(COMPILE_ARCH),x86_64)
++LIBDIR = lib64
++else
++LIBDIR = lib
++endif
++
+ # GNU MP configuration
+-GMP_LIB        := /usr/lib/libgmp.a
++GMP_LIB        := /usr/$(LIBDIR)/libgmp.a
+ GMP_HEADER     := /usr/include/gmp.h
+ 
+ # sources and objects
+diff -uprN tpm_emulator-0.3/README tpm_emulator-0.3-x86_64/README
+--- tpm_emulator-0.3/README    2006-01-10 04:21:45.000000000 -0800
++++ tpm_emulator-0.3-x86_64/README     2006-05-26 11:26:02.000000000 -0700
+@@ -43,6 +43,12 @@ Example:
+ GMP_LIB        := /usr/lib/libgmp.a
+ GMP_HEADER     := /usr/include/gmp.h
+ 
++GNU MP Library on 64 bit Systems
++--------------------------------------------------------------------------
++Some 64-bit kernels have problems with importing the user-space gmp 
++library (/usr/lib*/libgmp.a) into kernel space.  These kernels will require
++that the gmp library be recompiled for kernel space with -mcmodel=kernel.
++
+ Installation
+ --------------------------------------------------------------------------
+ The compilation and installation process uses the build environment for 
+diff -uprN tpm_emulator-0.3/tpm/tpm_credentials.c 
tpm_emulator-0.3-x86_64/tpm/tpm_credentials.c
+--- tpm_emulator-0.3/tpm/tpm_credentials.c     2006-01-10 04:21:45.000000000 
-0800
++++ tpm_emulator-0.3-x86_64/tpm/tpm_credentials.c      2006-05-26 
11:26:02.000000000 -0700
+@@ -47,16 +47,16 @@ int tpm_compute_pubkey_checksum(TPM_NONC
+ 
+ TPM_RESULT tpm_get_pubek(TPM_PUBKEY *pubEndorsementKey)
+ {
+-  UINT32 key_length;
++  size_t key_length;
+   if (!tpmData.permanent.data.endorsementKey.size) return TPM_NO_ENDORSEMENT;
+   /* setup TPM_PUBKEY structure */
+-  key_length = tpmData.permanent.data.endorsementKey.size;
+-  pubEndorsementKey->pubKey.keyLength = key_length >> 3;
++  pubEndorsementKey->pubKey.keyLength = 
tpmData.permanent.data.endorsementKey.size >> 3;
+   pubEndorsementKey->pubKey.key = 
tpm_malloc(pubEndorsementKey->pubKey.keyLength);
+   if (pubEndorsementKey->pubKey.key == NULL) return TPM_FAIL;
+   rsa_export_modulus(&tpmData.permanent.data.endorsementKey,
+-    pubEndorsementKey->pubKey.key,
+-    &pubEndorsementKey->pubKey.keyLength);
++                   pubEndorsementKey->pubKey.key,
++                   &key_length);
++  pubEndorsementKey->pubKey.keyLength = key_length;
+   pubEndorsementKey->algorithmParms.algorithmID = TPM_ALG_RSA;
+   pubEndorsementKey->algorithmParms.encScheme = TPM_ES_RSAESOAEP_SHA1_MGF1;
+   pubEndorsementKey->algorithmParms.sigScheme = TPM_SS_NONE;
+@@ -175,6 +175,7 @@ TPM_RESULT TPM_OwnerReadInternalPub(TPM_
+ {
+   TPM_RESULT res;
+   TPM_KEY_DATA *srk = &tpmData.permanent.data.srk;
++  size_t key_length;
+   info("TPM_OwnerReadInternalPub()");
+   /* verify authorization */
+   res = tpm_verify_auth(auth1, tpmData.permanent.data.ownerAuth, 
TPM_KH_OWNER);
+@@ -186,7 +187,8 @@ TPM_RESULT TPM_OwnerReadInternalPub(TPM_
+     publicPortion->pubKey.key = tpm_malloc(publicPortion->pubKey.keyLength);
+     if (publicPortion->pubKey.key == NULL) return TPM_FAIL;
+     rsa_export_modulus(&srk->key, publicPortion->pubKey.key, 
+-      &publicPortion->pubKey.keyLength);
++      &key_length);
++    publicPortion->pubKey.keyLength = key_length;
+     publicPortion->algorithmParms.algorithmID = TPM_ALG_RSA;
+     publicPortion->algorithmParms.encScheme = srk->encScheme;
+     publicPortion->algorithmParms.sigScheme = srk->sigScheme;
+diff -uprN tpm_emulator-0.3/tpm/tpm_crypto.c 
tpm_emulator-0.3-x86_64/tpm/tpm_crypto.c
+--- tpm_emulator-0.3/tpm/tpm_crypto.c  2006-01-10 04:21:45.000000000 -0800
++++ tpm_emulator-0.3-x86_64/tpm/tpm_crypto.c   2006-05-26 11:26:02.000000000 
-0700
+@@ -182,7 +182,8 @@ TPM_RESULT TPM_CertifyKey(TPM_KEY_HANDLE
+   TPM_KEY_DATA *cert, *key;
+   sha1_ctx_t sha1_ctx;
+   BYTE *buf, *p;
+-  UINT32 length;
++  UINT32 length32;
++  size_t length;
+   info("TPM_CertifyKey()");
+   /* get keys */
+   cert = tpm_get_key(certHandle);
+@@ -264,14 +265,15 @@ TPM_RESULT TPM_CertifyKey(TPM_KEY_HANDLE
+   /* compute the digest of the CERTIFY_INFO[2] structure and sign it */
+   length = sizeof_TPM_CERTIFY_INFO((*certifyInfo));
+   p = buf = tpm_malloc(length);
++  length32=(UINT32) length;
+   if (buf == NULL
+-      || tpm_marshal_TPM_CERTIFY_INFO(&p, &length, certifyInfo)) {
++      || tpm_marshal_TPM_CERTIFY_INFO(&p, &length32, certifyInfo)) {
+     free_TPM_KEY_PARMS(certifyInfo->algorithmParms);
+     return TPM_FAIL;
+   }
+   length = sizeof_TPM_CERTIFY_INFO((*certifyInfo));
+   sha1_init(&sha1_ctx);
+-  sha1_update(&sha1_ctx, buf, length);
++  sha1_update(&sha1_ctx, buf, (size_t) length);
+   sha1_final(&sha1_ctx, buf);
+   res = tpm_sign(cert, auth1, FALSE, buf, SHA1_DIGEST_LENGTH, outData, 
outDataSize);
+   tpm_free(buf);
+@@ -292,7 +294,8 @@ TPM_RESULT TPM_CertifyKey2(TPM_KEY_HANDL
+   TPM_KEY_DATA *cert, *key;
+   sha1_ctx_t sha1_ctx;
+   BYTE *buf, *p;
+-  UINT32 length;
++  size_t length;
++  UINT32 length32;
+   info("TPM_CertifyKey2()");
+   /* get keys */
+   cert = tpm_get_key(certHandle);
+@@ -362,8 +365,9 @@ TPM_RESULT TPM_CertifyKey2(TPM_KEY_HANDL
+   /* compute the digest of the CERTIFY_INFO[2] structure and sign it */
+   length = sizeof_TPM_CERTIFY_INFO((*certifyInfo));
+   p = buf = tpm_malloc(length);
++  length32 = (UINT32) length;
+   if (buf == NULL
+-      || tpm_marshal_TPM_CERTIFY_INFO(&p, &length, certifyInfo)) {
++      || tpm_marshal_TPM_CERTIFY_INFO(&p, &length32, certifyInfo)) {
+     free_TPM_KEY_PARMS(certifyInfo->algorithmParms);
+     return TPM_FAIL;
+   }
+diff -uprN tpm_emulator-0.3/tpm/tpm_data.c 
tpm_emulator-0.3-x86_64/tpm/tpm_data.c
+--- tpm_emulator-0.3/tpm/tpm_data.c    2006-01-10 04:21:45.000000000 -0800
++++ tpm_emulator-0.3-x86_64/tpm/tpm_data.c     2006-05-26 11:26:02.000000000 
-0700
+@@ -214,7 +214,7 @@ static int read_from_file(uint8_t **data
+ int tpm_store_permanent_data(void)
+ {
+   uint8_t *buf, *ptr;
+-  size_t buf_length, len;
++  UINT32 buf_length, len;
+ 
+   /* marshal data */
+   buf_length = len = sizeof_TPM_STCLEAR_FLAGS(tpmData.stclear.flags)
+@@ -242,13 +242,14 @@ int tpm_store_permanent_data(void)
+ int tpm_restore_permanent_data(void)
+ {
+   uint8_t *buf, *ptr;
+-  size_t buf_length, len;
++  size_t buf_length;
++  UINT32 len;
+   TPM_VERSION ver;
+ 
+   /* read data */
+   if (read_from_file(&buf, &buf_length)) return -1;
+   ptr = buf;
+-  len = buf_length;
++  len = (uint32_t) buf_length;
+   /* unmarshal data */
+   if (tpm_unmarshal_TPM_VERSION(&ptr, &len, &ver)
+       || memcmp(&ver, &tpmData.permanent.data.version, sizeof(TPM_VERSION))
+diff -uprN tpm_emulator-0.3/tpm/tpm_marshalling.c 
tpm_emulator-0.3-x86_64/tpm/tpm_marshalling.c
+--- tpm_emulator-0.3/tpm/tpm_marshalling.c     2006-01-10 04:21:45.000000000 
-0800
++++ tpm_emulator-0.3-x86_64/tpm/tpm_marshalling.c      2006-05-26 
11:26:02.000000000 -0700
+@@ -1212,7 +1212,7 @@ int tpm_unmarshal_TPM_STANY_FLAGS(BYTE *
+ 
+ int tpm_marshal_RSA(BYTE **ptr, UINT32 *length, rsa_private_key_t *v)
+ {
+-  UINT32 m_len, e_len, q_len;
++  size_t m_len, e_len, q_len;
+   if (*length < sizeof_RSA((*v))) return -1;
+   if (v->size > 0) {
+     rsa_export_modulus(v, &(*ptr)[6], &m_len);
+diff -uprN tpm_emulator-0.3/tpm/tpm_owner.c 
tpm_emulator-0.3-x86_64/tpm/tpm_owner.c
+--- tpm_emulator-0.3/tpm/tpm_owner.c   2006-01-10 04:21:45.000000000 -0800
++++ tpm_emulator-0.3-x86_64/tpm/tpm_owner.c    2006-05-26 11:26:02.000000000 
-0700
+@@ -108,7 +108,7 @@ TPM_RESULT TPM_TakeOwnership(TPM_PROTOCO
+   TPM_RESULT res;
+   rsa_private_key_t *ek = &tpmData.permanent.data.endorsementKey;
+   TPM_KEY_DATA *srk = &tpmData.permanent.data.srk;
+-  UINT32 buf_size = ek->size >> 3;
++  size_t buf_size = ek->size >> 3, key_length; 
+   BYTE buf[buf_size];
+ 
+   info("TPM_TakeOwnership()");
+@@ -172,7 +172,8 @@ TPM_RESULT TPM_TakeOwnership(TPM_PROTOCO
+     return TPM_FAIL;
+   }
+   rsa_export_modulus(&srk->key, srkPub->pubKey.key,
+-    &srkPub->pubKey.keyLength);
++                   &key_length);
++  srkPub->pubKey.keyLength = (UINT32) key_length;
+   /* setup tpmProof and set state to owned */
+   tpm_get_random_bytes(tpmData.permanent.data.tpmProof.nonce, 
+     sizeof(tpmData.permanent.data.tpmProof.nonce));
+diff -uprN tpm_emulator-0.3/tpm/tpm_storage.c 
tpm_emulator-0.3-x86_64/tpm/tpm_storage.c
+--- tpm_emulator-0.3/tpm/tpm_storage.c 2006-01-10 04:21:45.000000000 -0800
++++ tpm_emulator-0.3-x86_64/tpm/tpm_storage.c  2006-05-26 14:33:18.000000000 
-0700
+@@ -58,6 +58,7 @@ int encrypt_sealed_data(TPM_KEY_DATA *ke
+                         BYTE *enc, UINT32 *enc_size)
+ {
+   UINT32 len;
++  size_t enc_size32 = *enc_size;
+   BYTE *buf, *ptr;
+   rsa_public_key_t pub_key;
+   int scheme;
+@@ -72,7 +73,7 @@ int encrypt_sealed_data(TPM_KEY_DATA *ke
+   if (buf == NULL
+       || tpm_marshal_TPM_SEALED_DATA(&ptr, &len, seal)
+       || rsa_encrypt(&pub_key, scheme, buf, sizeof_TPM_SEALED_DATA((*seal)),
+-                     enc, enc_size)) {
++                     enc, &enc_size32)) {
+     tpm_free(buf);
+     rsa_release_public_key(&pub_key);
+     return -1;
+@@ -85,7 +86,8 @@ int encrypt_sealed_data(TPM_KEY_DATA *ke
+ int decrypt_sealed_data(TPM_KEY_DATA *key, BYTE *enc, UINT32 enc_size,
+                         TPM_SEALED_DATA *seal, BYTE **buf) 
+ {
+-  UINT32 len;
++  size_t len;
++  UINT32 len32;
+   BYTE *ptr;
+   int scheme;
+   switch (key->encScheme) {
+@@ -96,8 +98,12 @@ int decrypt_sealed_data(TPM_KEY_DATA *ke
+   len = enc_size;
+   *buf = ptr = tpm_malloc(len);
+   if (*buf == NULL
+-      || rsa_decrypt(&key->key, scheme, enc, enc_size, *buf, &len)
+-      || tpm_unmarshal_TPM_SEALED_DATA(&ptr, &len, seal)) {
++      || rsa_decrypt(&key->key, scheme, enc, enc_size, *buf, &len) ){
++    tpm_free(*buf);
++    return -1;
++  }
++  len32 = len;
++  if (tpm_unmarshal_TPM_SEALED_DATA(&ptr, &len32, seal)) {
+     tpm_free(*buf);
+     return -1;
+   }
+@@ -237,11 +243,12 @@ TPM_RESULT TPM_Unseal(TPM_KEY_HANDLE par
+ 
+ TPM_RESULT TPM_UnBind(TPM_KEY_HANDLE keyHandle, UINT32 inDataSize,
+                       BYTE *inData, TPM_AUTH *auth1, 
+-                      UINT32 *outDataSize, BYTE **outData)
++                      UINT32 *outDataSize32, BYTE **outData)
+ {
+   TPM_RESULT res;
+   TPM_KEY_DATA *key;
+   int scheme;
++  size_t outDataSize;
+   info("TPM_UnBind()");
+   /* get key */
+   key = tpm_get_key(keyHandle);
+@@ -258,8 +265,8 @@ TPM_RESULT TPM_UnBind(TPM_KEY_HANDLE key
+   /* the size of the input data muss be greater than zero */
+   if (inDataSize == 0) return TPM_BAD_PARAMETER;
+   /* decrypt data */
+-  *outDataSize = inDataSize;
+-  *outData = tpm_malloc(*outDataSize);
++  outDataSize = inDataSize;
++  *outData = tpm_malloc(outDataSize);
+   if (*outData == NULL) return TPM_FAIL;
+   switch (key->encScheme) {
+     case TPM_ES_RSAESOAEP_SHA1_MGF1: scheme = RSA_ES_OAEP_SHA1; break;
+@@ -267,20 +274,21 @@ TPM_RESULT TPM_UnBind(TPM_KEY_HANDLE key
+     default: tpm_free(*outData); return TPM_DECRYPT_ERROR;
+   }
+   if (rsa_decrypt(&key->key, scheme, inData, inDataSize, 
+-      *outData, outDataSize)) {
++      *outData, &outDataSize)) {
+     tpm_free(*outData);
+     return TPM_DECRYPT_ERROR;
+   }
+   /* verify data if it is of type TPM_BOUND_DATA */
+   if (key->encScheme == TPM_ES_RSAESOAEP_SHA1_MGF1 
+       || key->keyUsage != TPM_KEY_LEGACY) {
+-    if (*outDataSize < 5 || memcmp(*outData, "\x01\x01\00\x00\x02", 5) != 0) {
++    if (outDataSize < 5 || memcmp(*outData, "\x01\x01\00\x00\x02", 5) != 0) {
+       tpm_free(*outData);
+       return TPM_DECRYPT_ERROR;
+     }
+-    *outDataSize -= 5;
+-    memmove(*outData, &(*outData)[5], *outDataSize);
++    outDataSize -= 5;
++    memmove(*outData, &(*outData)[5], outDataSize);
+   }
++  *outDataSize32 = (UINT32) outDataSize;
+   return TPM_SUCCESS;
+ }
+ 
+@@ -311,12 +319,13 @@ static int verify_key_digest(TPM_KEY *ke
+ }
+ 
+ int encrypt_private_key(TPM_KEY_DATA *key, TPM_STORE_ASYMKEY *store,
+-                        BYTE *enc, UINT32 *enc_size)
++                        BYTE *enc, UINT32 *enc_size32)
+ {
+   UINT32 len;
+   BYTE *buf, *ptr;
+   rsa_public_key_t pub_key;
+   int scheme;
++  size_t enc_size;
+   switch (key->encScheme) {
+     case TPM_ES_RSAESOAEP_SHA1_MGF1: scheme = RSA_ES_OAEP_SHA1; break;
+     case TPM_ES_RSAESPKCSv15: scheme = RSA_ES_PKCSV15; break;
+@@ -328,11 +337,12 @@ int encrypt_private_key(TPM_KEY_DATA *ke
+   if (buf == NULL
+       || tpm_marshal_TPM_STORE_ASYMKEY(&ptr, &len, store)
+       || rsa_encrypt(&pub_key, scheme, buf, 
sizeof_TPM_STORE_ASYMKEY((*store)),
+-                     enc, enc_size)) {
++                     enc, &enc_size)) {
+     tpm_free(buf);
+     rsa_release_public_key(&pub_key);
+     return -1;
+   }
++  *enc_size32 = (UINT32) enc_size;
+   tpm_free(buf);
+   rsa_release_public_key(&pub_key);
+   return 0;
+@@ -341,7 +351,8 @@ int encrypt_private_key(TPM_KEY_DATA *ke
+ int decrypt_private_key(TPM_KEY_DATA *key, BYTE *enc, UINT32 enc_size, 
+                         TPM_STORE_ASYMKEY *store, BYTE **buf) 
+ {
+-  UINT32 len;
++  UINT32 len32;
++  size_t len;
+   BYTE *ptr;
+   int scheme;
+   switch (key->encScheme) {
+@@ -352,8 +363,12 @@ int decrypt_private_key(TPM_KEY_DATA *ke
+   len = enc_size;
+   *buf = ptr = tpm_malloc(len);
+   if (*buf == NULL
+-      || rsa_decrypt(&key->key, scheme, enc, enc_size, *buf, &len)
+-      || tpm_unmarshal_TPM_STORE_ASYMKEY(&ptr, &len, store)) {
++      || rsa_decrypt(&key->key, scheme, enc, enc_size, *buf, &len) ) {
++    tpm_free(*buf);
++    return -1;
++  }
++  len32 = (UINT32) len;
++  if (tpm_unmarshal_TPM_STORE_ASYMKEY(&ptr, &len32, store)) {  
+     tpm_free(*buf);
+     return -1;
+   }
+@@ -371,7 +386,7 @@ TPM_RESULT TPM_CreateWrapKey(TPM_KEY_HAN
+   TPM_SESSION_DATA *session;
+   TPM_STORE_ASYMKEY store;
+   rsa_private_key_t rsa;
+-  UINT32 key_length;
++  size_t key_length;
+ 
+   info("TPM_CreateWrapKey()");
+   /* get parent key */
+@@ -428,11 +443,11 @@ TPM_RESULT TPM_CreateWrapKey(TPM_KEY_HAN
+   }
+   if (compute_key_digest(wrappedKey, &store.pubDataDigest)) return TPM_FAIL;
+   /* generate key and store it */
+-  key_length = keyInfo->algorithmParms.parms.rsa.keyLength;
+-  if (rsa_generate_key(&rsa, key_length)) return TPM_FAIL;
+-  wrappedKey->pubKey.keyLength = key_length >> 3;
++  if (rsa_generate_key(&rsa, keyInfo->algorithmParms.parms.rsa.keyLength)) 
++    return TPM_FAIL;
++  wrappedKey->pubKey.keyLength = keyInfo->algorithmParms.parms.rsa.keyLength 
>> 3;
+   wrappedKey->pubKey.key = tpm_malloc(wrappedKey->pubKey.keyLength);
+-  store.privKey.keyLength = key_length >> 4;
++  store.privKey.keyLength = keyInfo->algorithmParms.parms.rsa.keyLength >> 4;
+   store.privKey.key = tpm_malloc(store.privKey.keyLength);
+   wrappedKey->encDataSize = parent->key.size >> 3;
+   wrappedKey->encData = tpm_malloc(wrappedKey->encDataSize);
+@@ -444,9 +459,11 @@ TPM_RESULT TPM_CreateWrapKey(TPM_KEY_HAN
+     tpm_free(wrappedKey->encData);
+     return TPM_FAIL;
+   }
+-  rsa_export_modulus(&rsa, wrappedKey->pubKey.key, 
+-    &wrappedKey->pubKey.keyLength);
+-  rsa_export_prime1(&rsa, store.privKey.key, &store.privKey.keyLength);
++  rsa_export_modulus(&rsa, wrappedKey->pubKey.key,
++                   &key_length);
++  wrappedKey->pubKey.keyLength = (UINT32) key_length;
++  rsa_export_prime1(&rsa, store.privKey.key, &key_length);
++  store.privKey.keyLength = (UINT32) key_length;
+   rsa_release_private_key(&rsa);
+   /* encrypt private key data */
+   if (encrypt_private_key(parent, &store, wrappedKey->encData, 
+@@ -567,6 +584,7 @@ TPM_RESULT TPM_LoadKey2(TPM_KEY_HANDLE p
+ 
+ int tpm_setup_key_parms(TPM_KEY_DATA *key, TPM_KEY_PARMS *parms)
+ {
++  size_t key_length;
+   parms->algorithmID = TPM_ALG_RSA;
+   parms->encScheme = key->encScheme;
+   parms->sigScheme = key->sigScheme;
+@@ -576,7 +594,8 @@ int tpm_setup_key_parms(TPM_KEY_DATA *ke
+   parms->parms.rsa.exponent = tpm_malloc(parms->parms.rsa.exponentSize);
+   if (parms->parms.rsa.exponent == NULL) return -1;
+   rsa_export_exponent(&key->key, parms->parms.rsa.exponent,
+-    &parms->parms.rsa.exponentSize);
++    &key_length);
++  parms->parms.rsa.exponentSize = (UINT32) key_length;
+   parms->parmSize = 12 + parms->parms.rsa.exponentSize;
+   return 0;
+ }
+@@ -587,6 +606,7 @@ TPM_RESULT TPM_GetPubKey(TPM_KEY_HANDLE 
+   TPM_RESULT res;
+   TPM_KEY_DATA *key;
+   TPM_DIGEST digest;
++  size_t key_length;
+   info("TPM_GetPubKey()");
+   /* get key */
+   if (keyHandle == TPM_KH_SRK) return TPM_BAD_PARAMETER;
+@@ -614,8 +634,8 @@ TPM_RESULT TPM_GetPubKey(TPM_KEY_HANDLE 
+   pubKey->pubKey.keyLength = key->key.size >> 3;
+   pubKey->pubKey.key = tpm_malloc(pubKey->pubKey.keyLength);
+   if (pubKey->pubKey.key == NULL) return TPM_FAIL;
+-  rsa_export_modulus(&key->key, pubKey->pubKey.key, 
+-    &pubKey->pubKey.keyLength);
++  rsa_export_modulus(&key->key, pubKey->pubKey.key, &key_length); 
++  pubKey->pubKey.keyLength = (UINT32) key_length;
+   if (tpm_setup_key_parms(key, &pubKey->algorithmParms) != 0) {
+     tpm_free(pubKey->pubKey.key);
+     return TPM_FAIL;
diff -r 3be4c8288737 -r acabf4bdec4f tools/vtpm/tpm_emulator-0.2b-x86_64.patch
--- a/tools/vtpm/tpm_emulator-0.2b-x86_64.patch Wed May 31 11:30:07 2006 -0600
+++ /dev/null   Thu Jan 01 00:00:00 1970 +0000
@@ -1,499 +0,0 @@
-diff -uprN tpm_emulator-0.2/crypto/gmp_kernel_wrapper.c 
tpm_emulator-0.2-x86_64/crypto/gmp_kernel_wrapper.c
---- tpm_emulator-0.2/crypto/gmp_kernel_wrapper.c       2005-08-15 
00:58:57.000000000 -0700
-+++ tpm_emulator-0.2-x86_64/crypto/gmp_kernel_wrapper.c        2005-09-19 
14:10:29.000000000 -0700
-@@ -79,7 +79,7 @@ void __attribute__ ((regparm(0))) *kerne
- {
-   void *ret  = (void*)kmalloc(size, GFP_KERNEL);
-   if (!ret) panic(KERN_CRIT TPM_MODULE_NAME 
--    "GMP: cannot allocate memory (size=%u)\n", size);
-+    "GMP: cannot allocate memory (size=%Zu)\n", size);
-   return ret;
- }
- 
-@@ -88,7 +88,7 @@ void __attribute__ ((regparm(0))) *kerne
- {
-   void *ret = (void*)kmalloc(new_size, GFP_KERNEL);
-   if (!ret) panic(KERN_CRIT TPM_MODULE_NAME "GMP: Cannot reallocate memory "
--    "(old_size=%u new_size=%u)\n", old_size, new_size);
-+    "(old_size=%Zu new_size=%Zu)\n", old_size, new_size);
-   memcpy(ret, oldptr, old_size);
-   kfree(oldptr);
-   return ret;
-diff -uprN tpm_emulator-0.2/linux_module.c 
tpm_emulator-0.2-x86_64/linux_module.c
---- tpm_emulator-0.2/linux_module.c    2005-08-15 00:58:57.000000000 -0700
-+++ tpm_emulator-0.2-x86_64/linux_module.c     2005-09-19 14:10:29.000000000 
-0700
-@@ -66,7 +66,7 @@ static int tpm_release(struct inode *ino
- 
- static ssize_t tpm_read(struct file *file, char *buf, size_t count, loff_t 
*ppos)
- {
--  debug("%s(%d)", __FUNCTION__, count);
-+  debug("%s(%Zu)", __FUNCTION__, count);
-   down(&tpm_mutex);
-   if (tpm_response.data != NULL) {
-     count = min(count, (size_t)tpm_response.size - (size_t)*ppos);
-@@ -81,7 +81,7 @@ static ssize_t tpm_read(struct file *fil
- 
- static ssize_t tpm_write(struct file *file, const char *buf, size_t count, 
loff_t *ppos)
- {
--  debug("%s(%d)", __FUNCTION__, count);
-+  debug("%s(%Zu)", __FUNCTION__, count);
-   down(&tpm_mutex);
-   *ppos = 0;
-   if (tpm_response.data != NULL) kfree(tpm_response.data);
-diff -uprN tpm_emulator-0.2/linux_module.h 
tpm_emulator-0.2-x86_64/linux_module.h
---- tpm_emulator-0.2/linux_module.h    2005-08-15 00:58:57.000000000 -0700
-+++ tpm_emulator-0.2-x86_64/linux_module.h     2005-09-19 14:10:29.000000000 
-0700
-@@ -28,8 +28,10 @@
- 
- /* module settings */
- 
-+#ifndef STR
- #define STR(s) __STR__(s)
- #define __STR__(s) #s
-+#endif
- #include "tpm_version.h"
- 
- #define TPM_DEVICE_MINOR      224
-diff -uprN tpm_emulator-0.2/Makefile tpm_emulator-0.2-x86_64/Makefile
---- tpm_emulator-0.2/Makefile  2005-08-15 00:58:57.000000000 -0700
-+++ tpm_emulator-0.2-x86_64/Makefile   2005-09-19 14:10:29.000000000 -0700
-@@ -7,6 +7,7 @@
- KERNEL_RELEASE := $(shell uname -r)
- KERNEL_BUILD   := /lib/modules/$(KERNEL_RELEASE)/build
- MOD_SUBDIR     := misc
-+COMPILE_ARCH    ?= $(shell uname -m | sed -e s/i.86/x86_32/)
- 
- # module settings
- MODULE_NAME    := tpm_emulator
-@@ -17,8 +18,14 @@ VERSION_BUILD  := $(shell date +"%s")
- # enable/disable DEBUG messages
- EXTRA_CFLAGS   += -DDEBUG -g  
- 
-+ifeq ($(COMPILE_ARCH),x86_64)
-+LIBDIR = lib64
-+else
-+LIBDIR = lib
-+endif
-+
- # GNU MP configuration
--GMP_LIB        := /usr/lib/libgmp.a
-+GMP_LIB        := /usr/$(LIBDIR)/libgmp.a
- GMP_HEADER     := /usr/include/gmp.h
- 
- # sources and objects
-diff -uprN tpm_emulator-0.2/README tpm_emulator-0.2-x86_64/README
---- tpm_emulator-0.2/README    2005-08-15 00:58:57.000000000 -0700
-+++ tpm_emulator-0.2-x86_64/README     2005-09-19 14:21:43.000000000 -0700
-@@ -45,6 +45,12 @@ Example:
- GMP_LIB        := /usr/lib/libgmp.a
- GMP_HEADER     := /usr/include/gmp.h
- 
-+GNU MP Library on 64 bit Systems
-+--------------------------------------------------------------------------
-+Some 64-bit kernels have problems with importing the user-space gmp 
-+library (/usr/lib*/libgmp.a) into kernel space.  These kernels will require
-+that the gmp library be recompiled for kernel space with -mcmodel=kernel.
-+
- Installation
- --------------------------------------------------------------------------
- The compilation and installation process uses the build environment for 
-diff -uprN tpm_emulator-0.2/tpm/tpm_credentials.c 
tpm_emulator-0.2-x86_64/tpm/tpm_credentials.c
---- tpm_emulator-0.2/tpm/tpm_credentials.c     2005-08-15 00:58:57.000000000 
-0700
-+++ tpm_emulator-0.2-x86_64/tpm/tpm_credentials.c      2005-09-19 
14:10:29.000000000 -0700
-@@ -47,16 +47,16 @@ int tpm_compute_pubkey_checksum(TPM_NONC
- 
- TPM_RESULT tpm_get_pubek(TPM_PUBKEY *pubEndorsementKey)
- {
--  UINT32 key_length;
-+  size_t key_length;
-   if (!tpmData.permanent.data.endorsementKey.size) return TPM_NO_ENDORSEMENT;
-   /* setup TPM_PUBKEY structure */
--  key_length = tpmData.permanent.data.endorsementKey.size;
--  pubEndorsementKey->pubKey.keyLength = key_length >> 3;
-+  pubEndorsementKey->pubKey.keyLength = 
tpmData.permanent.data.endorsementKey.size >> 3;
-   pubEndorsementKey->pubKey.key = 
tpm_malloc(pubEndorsementKey->pubKey.keyLength);
-   if (pubEndorsementKey->pubKey.key == NULL) return TPM_FAIL;
-   rsa_export_modulus(&tpmData.permanent.data.endorsementKey,
--    pubEndorsementKey->pubKey.key,
--    &pubEndorsementKey->pubKey.keyLength);
-+                   pubEndorsementKey->pubKey.key,
-+                   &key_length);
-+  pubEndorsementKey->pubKey.keyLength = key_length;
-   pubEndorsementKey->algorithmParms.algorithmID = TPM_ALG_RSA;
-   pubEndorsementKey->algorithmParms.encScheme = TPM_ES_RSAESOAEP_SHA1_MGF1;
-   pubEndorsementKey->algorithmParms.sigScheme = TPM_SS_NONE;
-@@ -169,6 +169,7 @@ TPM_RESULT TPM_OwnerReadInternalPub(TPM_
- {
-   TPM_RESULT res;
-   TPM_KEY_DATA *srk = &tpmData.permanent.data.srk;
-+  size_t key_length;
-   info("TPM_OwnerReadInternalPub()");
-   /* verify authorization */
-   res = tpm_verify_auth(auth1, tpmData.permanent.data.ownerAuth, 
TPM_KH_OWNER);
-@@ -180,7 +181,8 @@ TPM_RESULT TPM_OwnerReadInternalPub(TPM_
-     publicPortion->pubKey.key = tpm_malloc(publicPortion->pubKey.keyLength);
-     if (publicPortion->pubKey.key == NULL) return TPM_FAIL;
-     rsa_export_modulus(&srk->key, publicPortion->pubKey.key, 
--      &publicPortion->pubKey.keyLength);
-+      &key_length);
-+    publicPortion->pubKey.keyLength = key_length;
-     publicPortion->algorithmParms.algorithmID = TPM_ALG_RSA;
-     publicPortion->algorithmParms.encScheme = srk->encScheme;
-     publicPortion->algorithmParms.sigScheme = srk->sigScheme;
-diff -uprN tpm_emulator-0.2/tpm/tpm_crypto.c 
tpm_emulator-0.2-x86_64/tpm/tpm_crypto.c
---- tpm_emulator-0.2/tpm/tpm_crypto.c  2005-08-15 00:58:57.000000000 -0700
-+++ tpm_emulator-0.2-x86_64/tpm/tpm_crypto.c   2005-09-19 14:10:29.000000000 
-0700
-@@ -182,7 +182,8 @@ TPM_RESULT TPM_CertifyKey(TPM_KEY_HANDLE
-   TPM_KEY_DATA *cert, *key;
-   sha1_ctx_t sha1_ctx;
-   BYTE *buf, *p;
--  UINT32 length;
-+  UINT32 length32;
-+  size_t length;
-   info("TPM_CertifyKey()");
-   /* get keys */
-   cert = tpm_get_key(certHandle);
-@@ -264,14 +265,15 @@ TPM_RESULT TPM_CertifyKey(TPM_KEY_HANDLE
-   /* compute the digest of the CERTIFY_INFO[2] structure and sign it */
-   length = sizeof_TPM_CERTIFY_INFO((*certifyInfo));
-   p = buf = tpm_malloc(length);
-+  length32=(UINT32) length;
-   if (buf == NULL
--      || tpm_marshal_TPM_CERTIFY_INFO(&p, &length, certifyInfo)) {
-+      || tpm_marshal_TPM_CERTIFY_INFO(&p, &length32, certifyInfo)) {
-     free_TPM_KEY_PARMS(certifyInfo->algorithmParms);
-     return TPM_FAIL;
-   }
-   length = sizeof_TPM_CERTIFY_INFO((*certifyInfo));
-   sha1_init(&sha1_ctx);
--  sha1_update(&sha1_ctx, buf, length);
-+  sha1_update(&sha1_ctx, buf, (size_t) length);
-   sha1_final(&sha1_ctx, buf);
-   res = tpm_sign(cert, auth1, FALSE, buf, SHA1_DIGEST_LENGTH, outData, 
outDataSize);
-   tpm_free(buf);
-@@ -292,7 +294,8 @@ TPM_RESULT TPM_CertifyKey2(TPM_KEY_HANDL
-   TPM_KEY_DATA *cert, *key;
-   sha1_ctx_t sha1_ctx;
-   BYTE *buf, *p;
--  UINT32 length;
-+  size_t length;
-+  UINT32 length32;
-   info("TPM_CertifyKey2()");
-   /* get keys */
-   cert = tpm_get_key(certHandle);
-@@ -362,8 +365,9 @@ TPM_RESULT TPM_CertifyKey2(TPM_KEY_HANDL
-   /* compute the digest of the CERTIFY_INFO[2] structure and sign it */
-   length = sizeof_TPM_CERTIFY_INFO((*certifyInfo));
-   p = buf = tpm_malloc(length);
-+  length32 = (UINT32) length;
-   if (buf == NULL
--      || tpm_marshal_TPM_CERTIFY_INFO(&p, &length, certifyInfo)) {
-+      || tpm_marshal_TPM_CERTIFY_INFO(&p, &length32, certifyInfo)) {
-     free_TPM_KEY_PARMS(certifyInfo->algorithmParms);
-     return TPM_FAIL;
-   }
-diff -uprN tpm_emulator-0.2/tpm/tpm_data.c 
tpm_emulator-0.2-x86_64/tpm/tpm_data.c
---- tpm_emulator-0.2/tpm/tpm_data.c    2005-08-15 00:58:57.000000000 -0700
-+++ tpm_emulator-0.2-x86_64/tpm/tpm_data.c     2005-09-19 14:10:29.000000000 
-0700
-@@ -179,7 +179,7 @@ static int read_from_file(uint8_t **data
- int tpm_store_permanent_data(void)
- {
-   uint8_t *buf, *ptr;
--  size_t buf_length, len;
-+  UINT32 buf_length, len;
- 
-   /* marshal data */
-   buf_length = len = sizeof_TPM_STCLEAR_FLAGS(tpmData.stclear.flags)
-@@ -207,13 +207,14 @@ int tpm_store_permanent_data(void)
- int tpm_restore_permanent_data(void)
- {
-   uint8_t *buf, *ptr;
--  size_t buf_length, len;
-+  size_t buf_length;
-+  UINT32 len;
-   TPM_VERSION ver;
- 
-   /* read data */
-   if (read_from_file(&buf, &buf_length)) return -1;
-   ptr = buf;
--  len = buf_length;
-+  len = (uint32_t) buf_length;
-   /* unmarshal data */
-   if (tpm_unmarshal_TPM_VERSION(&ptr, &len, &ver)
-       || memcmp(&ver, &tpmData.permanent.data.version, sizeof(TPM_VERSION))
-diff -uprN tpm_emulator-0.2/tpm/tpm_marshalling.c 
tpm_emulator-0.2-x86_64/tpm/tpm_marshalling.c
---- tpm_emulator-0.2/tpm/tpm_marshalling.c     2005-08-15 00:58:57.000000000 
-0700
-+++ tpm_emulator-0.2-x86_64/tpm/tpm_marshalling.c      2005-09-19 
14:10:29.000000000 -0700
-@@ -981,7 +981,7 @@ int tpm_unmarshal_TPM_STANY_FLAGS(BYTE *
- 
- int tpm_marshal_RSA(BYTE **ptr, UINT32 *length, rsa_private_key_t *v)
- {
--  UINT32 m_len, e_len, q_len;
-+  size_t m_len, e_len, q_len;
-   if (*length < sizeof_RSA((*v))) return -1;
-   if (v->size > 0) {
-     rsa_export_modulus(v, &(*ptr)[6], &m_len);
-diff -uprN tpm_emulator-0.2/tpm/tpm_owner.c 
tpm_emulator-0.2-x86_64/tpm/tpm_owner.c
---- tpm_emulator-0.2/tpm/tpm_owner.c   2005-08-15 00:58:57.000000000 -0700
-+++ tpm_emulator-0.2-x86_64/tpm/tpm_owner.c    2005-09-19 14:10:29.000000000 
-0700
-@@ -108,7 +108,7 @@ TPM_RESULT TPM_TakeOwnership(TPM_PROTOCO
-   TPM_RESULT res;
-   rsa_private_key_t *ek = &tpmData.permanent.data.endorsementKey;
-   TPM_KEY_DATA *srk = &tpmData.permanent.data.srk;
--  UINT32 buf_size = ek->size >> 3;
-+  size_t buf_size = ek->size >> 3, key_length; 
-   BYTE buf[buf_size];
- 
-   info("TPM_TakeOwnership()");
-@@ -172,7 +172,8 @@ TPM_RESULT TPM_TakeOwnership(TPM_PROTOCO
-     return TPM_FAIL;
-   }
-   rsa_export_modulus(&srk->key, srkPub->pubKey.key,
--    &srkPub->pubKey.keyLength);
-+                   &key_length);
-+  srkPub->pubKey.keyLength = (UINT32) key_length;
-   /* setup tpmProof and set state to owned */
-   tpm_get_random_bytes(tpmData.permanent.data.tpmProof.nonce, 
-     sizeof(tpmData.permanent.data.tpmProof.nonce));
-diff -uprN tpm_emulator-0.2/tpm/tpm_storage.c 
tpm_emulator-0.2-x86_64/tpm/tpm_storage.c
---- tpm_emulator-0.2/tpm/tpm_storage.c 2005-08-15 00:58:57.000000000 -0700
-+++ tpm_emulator-0.2-x86_64/tpm/tpm_storage.c  2005-09-19 14:10:29.000000000 
-0700
-@@ -58,6 +58,7 @@ int encrypt_sealed_data(TPM_KEY_DATA *ke
-                         BYTE *enc, UINT32 *enc_size)
- {
-   UINT32 len;
-+  size_t enc_size32 = *enc_size;
-   BYTE *buf, *ptr;
-   rsa_public_key_t pub_key;
-   int scheme;
-@@ -72,7 +73,7 @@ int encrypt_sealed_data(TPM_KEY_DATA *ke
-   if (buf == NULL
-       || tpm_marshal_TPM_SEALED_DATA(&ptr, &len, seal)
-       || rsa_encrypt(&pub_key, scheme, buf, sizeof_TPM_SEALED_DATA((*seal)),
--                     enc, enc_size)) {
-+                     enc, &enc_size32)) {
-     tpm_free(buf);
-     rsa_release_public_key(&pub_key);
-     return -1;
-@@ -85,7 +86,8 @@ int encrypt_sealed_data(TPM_KEY_DATA *ke
- int decrypt_sealed_data(TPM_KEY_DATA *key, BYTE *enc, UINT32 enc_size,
-                         TPM_SEALED_DATA *seal, BYTE **buf) 
- {
--  UINT32 len;
-+  size_t len;
-+  UINT32 len32;
-   BYTE *ptr;
-   int scheme;
-   switch (key->encScheme) {
-@@ -96,8 +98,12 @@ int decrypt_sealed_data(TPM_KEY_DATA *ke
-   len = enc_size;
-   *buf = ptr = tpm_malloc(len);
-   if (*buf == NULL
--      || rsa_decrypt(&key->key, scheme, enc, enc_size, *buf, &len)
--      || tpm_unmarshal_TPM_SEALED_DATA(&ptr, &len, seal)) {
-+      || rsa_decrypt(&key->key, scheme, enc, enc_size, *buf, &len) ){
-+    tpm_free(*buf);
-+    return -1;
-+  }
-+  len32 = len;
-+  if (tpm_unmarshal_TPM_SEALED_DATA(&ptr, &len32, seal)) {
-     tpm_free(*buf);
-     return -1;
-   }
-@@ -237,11 +243,12 @@ TPM_RESULT TPM_Unseal(TPM_KEY_HANDLE par
- 
- TPM_RESULT TPM_UnBind(TPM_KEY_HANDLE keyHandle, UINT32 inDataSize,
-                       BYTE *inData, TPM_AUTH *auth1, 
--                      UINT32 *outDataSize, BYTE **outData)
-+                      UINT32 *outDataSize32, BYTE **outData)
- {
-   TPM_RESULT res;
-   TPM_KEY_DATA *key;
-   int scheme;
-+  size_t outDataSize;
-   info("TPM_UnBind()");
-   /* get key */
-   key = tpm_get_key(keyHandle);
-@@ -258,8 +265,8 @@ TPM_RESULT TPM_UnBind(TPM_KEY_HANDLE key
-   /* the size of the input data muss be greater than zero */
-   if (inDataSize == 0) return TPM_BAD_PARAMETER;
-   /* decrypt data */
--  *outDataSize = inDataSize;
--  *outData = tpm_malloc(*outDataSize);
-+  outDataSize = inDataSize;
-+  *outData = tpm_malloc(outDataSize);
-   if (*outData == NULL) return TPM_FAIL;
-   switch (key->encScheme) {
-     case TPM_ES_RSAESOAEP_SHA1_MGF1: scheme = RSA_ES_OAEP_SHA1; break;
-@@ -267,20 +274,21 @@ TPM_RESULT TPM_UnBind(TPM_KEY_HANDLE key
-     default: tpm_free(*outData); return TPM_DECRYPT_ERROR;
-   }
-   if (rsa_decrypt(&key->key, scheme, inData, inDataSize, 
--      *outData, outDataSize)) {
-+                *outData, &outDataSize) ) { 
-     tpm_free(*outData);
-     return TPM_DECRYPT_ERROR;
-   }
-   /* verify data if it is of type TPM_BOUND_DATA */
-   if (key->encScheme == TPM_ES_RSAESOAEP_SHA1_MGF1 
-       || key->keyUsage != TPM_KEY_LEGACY) {
--    if (*outDataSize < 5 || memcmp(*outData, "\x01\x01\00\x00\x02", 5) != 0) {
-+    if (outDataSize < 5 || memcmp(*outData, "\x01\x01\00\x00\x02", 5) != 0) {
-       tpm_free(*outData);
-       return TPM_DECRYPT_ERROR;
-     }
--    *outDataSize -= 5;
--    memmove(*outData, &(*outData)[5], *outDataSize);   
--  } 
-+    outDataSize -= 5;
-+    memmove(*outData, &(*outData)[5], outDataSize);   
-+  }
-+  *outDataSize32 = (UINT32) outDataSize; 
-   return TPM_SUCCESS;
- }
- 
-@@ -311,12 +319,13 @@ static int verify_key_digest(TPM_KEY *ke
- }
- 
- int encrypt_private_key(TPM_KEY_DATA *key, TPM_STORE_ASYMKEY *store,
--                        BYTE *enc, UINT32 *enc_size)
-+                        BYTE *enc, UINT32 *enc_size32)
- {
-   UINT32 len;
-   BYTE *buf, *ptr;
-   rsa_public_key_t pub_key;
-   int scheme;
-+  size_t enc_size;
-   switch (key->encScheme) {
-     case TPM_ES_RSAESOAEP_SHA1_MGF1: scheme = RSA_ES_OAEP_SHA1; break;
-     case TPM_ES_RSAESPKCSv15: scheme = RSA_ES_PKCSV15; break;
-@@ -328,11 +337,12 @@ int encrypt_private_key(TPM_KEY_DATA *ke
-   if (buf == NULL
-       || tpm_marshal_TPM_STORE_ASYMKEY(&ptr, &len, store)
-       || rsa_encrypt(&pub_key, scheme, buf, 
sizeof_TPM_STORE_ASYMKEY((*store)),
--                     enc, enc_size)) {
-+                     enc, &enc_size)) {
-     tpm_free(buf);
-     rsa_release_public_key(&pub_key);
-     return -1;
-   }
-+  *enc_size32 = (UINT32) enc_size;
-   tpm_free(buf);
-   rsa_release_public_key(&pub_key);
-   return 0;
-@@ -341,7 +351,8 @@ int encrypt_private_key(TPM_KEY_DATA *ke
- int decrypt_private_key(TPM_KEY_DATA *key, BYTE *enc, UINT32 enc_size, 
-                         TPM_STORE_ASYMKEY *store, BYTE **buf) 
- {
--  UINT32 len;
-+  UINT32 len32;
-+  size_t len;
-   BYTE *ptr;
-   int scheme;
-   switch (key->encScheme) {
-@@ -352,11 +363,16 @@ int decrypt_private_key(TPM_KEY_DATA *ke
-   len = enc_size;
-   *buf = ptr = tpm_malloc(len);
-   if (*buf == NULL
--      || rsa_decrypt(&key->key, scheme, enc, enc_size, *buf, &len)
--      || tpm_unmarshal_TPM_STORE_ASYMKEY(&ptr, &len, store)) {
-+      || rsa_decrypt(&key->key, scheme, enc, enc_size, *buf, &len) ) {
-+    tpm_free(*buf);
-+    return -1;
-+  }
-+  len32 = (UINT32) len;
-+  if (tpm_unmarshal_TPM_STORE_ASYMKEY(&ptr, &len32, store)) {  
-     tpm_free(*buf);
-     return -1;
-   }
-+
-   return 0;
- }
- 
-@@ -371,7 +387,7 @@ TPM_RESULT TPM_CreateWrapKey(TPM_KEY_HAN
-   TPM_SESSION_DATA *session;
-   TPM_STORE_ASYMKEY store;
-   rsa_private_key_t rsa;
--  UINT32 key_length;
-+  size_t key_length;
- 
-   info("TPM_CreateWrapKey()");
-   /* get parent key */
-@@ -428,11 +444,11 @@ TPM_RESULT TPM_CreateWrapKey(TPM_KEY_HAN
-   }
-   if (compute_key_digest(wrappedKey, &store.pubDataDigest)) return TPM_FAIL;
-   /* generate key and store it */
--  key_length = keyInfo->algorithmParms.parms.rsa.keyLength;
--  if (rsa_generate_key(&rsa, key_length)) return TPM_FAIL;
--  wrappedKey->pubKey.keyLength = key_length >> 3;
-+  if (rsa_generate_key(&rsa, keyInfo->algorithmParms.parms.rsa.keyLength)) 
-+    return TPM_FAIL;
-+  wrappedKey->pubKey.keyLength = keyInfo->algorithmParms.parms.rsa.keyLength 
>> 3;
-   wrappedKey->pubKey.key = tpm_malloc(wrappedKey->pubKey.keyLength);
--  store.privKey.keyLength = key_length >> 4;
-+  store.privKey.keyLength = keyInfo->algorithmParms.parms.rsa.keyLength >> 4;
-   store.privKey.key = tpm_malloc(store.privKey.keyLength);
-   wrappedKey->encDataSize = parent->key.size >> 3;
-   wrappedKey->encData = tpm_malloc(wrappedKey->encDataSize);
-@@ -444,9 +460,11 @@ TPM_RESULT TPM_CreateWrapKey(TPM_KEY_HAN
-     tpm_free(wrappedKey->encData);
-     return TPM_FAIL;
-   }
--  rsa_export_modulus(&rsa, wrappedKey->pubKey.key, 
--    &wrappedKey->pubKey.keyLength);
--  rsa_export_prime1(&rsa, store.privKey.key, &store.privKey.keyLength);
-+  rsa_export_modulus(&rsa, wrappedKey->pubKey.key,
-+                   &key_length);
-+  wrappedKey->pubKey.keyLength = (UINT32) key_length;
-+  rsa_export_prime1(&rsa, store.privKey.key, &key_length);
-+  store.privKey.keyLength = (UINT32) key_length;
-   rsa_release_private_key(&rsa);
-   /* encrypt private key data */
-   if (encrypt_private_key(parent, &store, wrappedKey->encData, 
-@@ -560,6 +578,7 @@ TPM_RESULT TPM_LoadKey(TPM_KEY_HANDLE pa
- 
- int tpm_setup_key_parms(TPM_KEY_DATA *key, TPM_KEY_PARMS *parms)
- {
-+  size_t key_length;
-   parms->algorithmID = TPM_ALG_RSA;
-   parms->encScheme = key->encScheme;
-   parms->sigScheme = key->sigScheme;
-@@ -569,7 +588,8 @@ int tpm_setup_key_parms(TPM_KEY_DATA *ke
-   parms->parms.rsa.exponent = tpm_malloc(parms->parms.rsa.exponentSize);
-   if (parms->parms.rsa.exponent == NULL) return -1;
-   rsa_export_exponent(&key->key, parms->parms.rsa.exponent,
--    &parms->parms.rsa.exponentSize);
-+                      &key_length);  
-+  parms->parms.rsa.exponentSize = (UINT32) key_length;
-   parms->parmSize = 12 + parms->parms.rsa.exponentSize;  
-   return 0;
- }
-@@ -580,6 +600,7 @@ TPM_RESULT TPM_GetPubKey(TPM_KEY_HANDLE 
-   TPM_RESULT res;
-   TPM_KEY_DATA *key;
-   TPM_DIGEST digest;
-+  size_t key_length;
-   info("TPM_GetPubKey()");
-   /* get key */
-   if (keyHandle == TPM_KH_SRK) return TPM_BAD_PARAMETER;
-@@ -607,8 +628,8 @@ TPM_RESULT TPM_GetPubKey(TPM_KEY_HANDLE 
-   pubKey->pubKey.keyLength = key->key.size >> 3;
-   pubKey->pubKey.key = tpm_malloc(pubKey->pubKey.keyLength);
-   if (pubKey->pubKey.key == NULL) return TPM_FAIL;
--  rsa_export_modulus(&key->key, pubKey->pubKey.key, 
--    &pubKey->pubKey.keyLength);
-+  rsa_export_modulus(&key->key, pubKey->pubKey.key, &key_length); 
-+  pubKey->pubKey.keyLength = (UINT32) key_length;
-   if (tpm_setup_key_parms(key, &pubKey->algorithmParms) != 0) {
-     tpm_free(pubKey->pubKey.key);
-     return TPM_FAIL;  
-diff -uprN tpm_emulator-0.2/tpm_version.h tpm_emulator-0.2-x86_64/tpm_version.h
---- tpm_emulator-0.2/tpm_version.h     2005-08-15 00:58:57.000000000 -0700
-+++ tpm_emulator-0.2-x86_64/tpm_version.h      1969-12-31 16:00:00.000000000 
-0800
-@@ -1,6 +0,0 @@
--#ifndef _TPM_VERSION_H_
--#define _TPM_VERSION_H_
--#define VERSION_MAJOR 0
--#define VERSION_MINOR 2
--#define VERSION_BUILD 1123950310
--#endif /* _TPM_VERSION_H_ */

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

<Prev in Thread] Current Thread [Next in Thread>