direct-io.hg

changeset 10233:acabf4bdec4f

merge with xen-unstable.hg
author awilliam@xenbuild.aw
date Wed May 31 13:05:21 2006 -0600 (2006-05-31)
parents 3be4c8288737 0ec4b9dfd5b4
children 671e8bd80d9a
files linux-2.6-xen-sparse/include/asm-ia64/hypercall.h tools/vtpm/tpm_emulator-0.2b-x86_64.patch
line diff
     1.1 --- a/.hgignore	Wed May 31 11:30:07 2006 -0600
     1.2 +++ b/.hgignore	Wed May 31 13:05:21 2006 -0600
     1.3 @@ -113,9 +113,9 @@
     1.4  ^tools/firmware/acpi/acpigen$
     1.5  ^tools/firmware/hvmloader/hvmloader$
     1.6  ^tools/firmware/hvmloader/roms\.h$
     1.7 -^tools/firmware/rombios/BIOS-bochs-latest$
     1.8 -^tools/firmware/rombios/_rombios_\.c$
     1.9 -^tools/firmware/rombios/rombios\.s$
    1.10 +^tools/firmware/rombios/BIOS-bochs-[^/]*$
    1.11 +^tools/firmware/rombios/_rombios[^/]*_\.c$
    1.12 +^tools/firmware/rombios/rombios[^/]*\.s$
    1.13  ^tools/firmware/vmxassist/acpi\.h$
    1.14  ^tools/firmware/vmxassist/gen$
    1.15  ^tools/firmware/vmxassist/offsets\.h$
     2.1 --- a/Config.mk	Wed May 31 11:30:07 2006 -0600
     2.2 +++ b/Config.mk	Wed May 31 13:05:21 2006 -0600
     2.3 @@ -39,19 +39,7 @@ else
     2.4  CFLAGS    += -g
     2.5  endif
     2.6  
     2.7 -ifeq ($(XEN_TARGET_ARCH),x86_32)
     2.8 -CFLAGS  += -m32 -march=i686
     2.9 -endif
    2.10 -
    2.11 -ifeq ($(XEN_TARGET_ARCH),x86_64)
    2.12 -CFLAGS  += -m64
    2.13 -endif
    2.14 -
    2.15 -ifeq ($(XEN_TARGET_ARCH),x86_64)
    2.16 -LIBDIR = lib64
    2.17 -else
    2.18 -LIBDIR = lib
    2.19 -endif
    2.20 +include $(XEN_ROOT)/config/$(XEN_TARGET_ARCH).mk
    2.21  
    2.22  ifneq ($(EXTRA_PREFIX),)
    2.23  EXTRA_INCLUDES += $(EXTRA_PREFIX)/include
     3.1 --- a/Makefile	Wed May 31 11:30:07 2006 -0600
     3.2 +++ b/Makefile	Wed May 31 13:05:21 2006 -0600
     3.3 @@ -17,7 +17,7 @@ endif
     3.4  .PHONY: all
     3.5  all: dist
     3.6  
     3.7 -XEN_ROOT=$(CURDIR)
     3.8 +export XEN_ROOT=$(CURDIR)
     3.9  include Config.mk
    3.10  include buildconfigs/Rules.mk
    3.11  
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/config/ia64.mk	Wed May 31 13:05:21 2006 -0600
     4.3 @@ -0,0 +1,4 @@
     4.4 +CONFIG_IA64 := y
     4.5 +CONFIG_IOEMU := y
     4.6 +
     4.7 +LIBDIR := lib
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/config/x86_32.mk	Wed May 31 13:05:21 2006 -0600
     5.3 @@ -0,0 +1,9 @@
     5.4 +CONFIG_X86 := y
     5.5 +CONFIG_PLAN9 := y
     5.6 +CONFIG_HVM := y
     5.7 +CONFIG_MIGRATE := y
     5.8 +CONFIG_IOEMU := y
     5.9 +CONFIG_MBOOTPACK := y
    5.10 +
    5.11 +CFLAGS += -m32 -march=i686
    5.12 +LIBDIR := lib
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/config/x86_64.mk	Wed May 31 13:05:21 2006 -0600
     6.3 @@ -0,0 +1,9 @@
     6.4 +CONFIG_X86 := y
     6.5 +CONFIG_PLAN9 := y
     6.6 +CONFIG_HVM := y
     6.7 +CONFIG_MIGRATE := y
     6.8 +CONFIG_IOEMU := y
     6.9 +CONFIG_MBOOTPACK := y
    6.10 +
    6.11 +CFLAGS += -m64
    6.12 +LIBDIR = lib64
     7.1 --- a/docs/src/interface.tex	Wed May 31 11:30:07 2006 -0600
     7.2 +++ b/docs/src/interface.tex	Wed May 31 13:05:21 2006 -0600
     7.3 @@ -205,30 +205,23 @@ event sent at a specified system time by
     7.4  implement timeout values when they block.
     7.5  
     7.6  
     7.7 -
     7.8 -%% % akw: demoting this to a section -- not sure if there is any point
     7.9 -%% % though, maybe just remove it.
    7.10 -
    7.11 -% KAF: Remove these random sections!
    7.12 -\begin{comment}
    7.13  \section{Xen CPU Scheduling}
    7.14  
    7.15  Xen offers a uniform API for CPU schedulers.  It is possible to choose
    7.16  from a number of schedulers at boot and it should be easy to add more.
    7.17 -The BVT, Atropos and Round Robin schedulers are part of the normal Xen
    7.18 -distribution.  BVT provides proportional fair shares of the CPU to the
    7.19 -running domains.  Atropos can be used to reserve absolute shares of
    7.20 -the CPU for each domain.  Round-robin is provided as an example of
    7.21 -Xen's internal scheduler API.
    7.22 +The SEDF, BVT, and Credit schedulers are part of the normal Xen
    7.23 +distribution.  BVT and SEDF will be going away and their use should be
    7.24 +avoided once the credit scheduler has stabilized and become the default.
    7.25 +The Credit scheduler provides proportional fair shares of the
    7.26 +host's CPUs to the running domains. It does this while transparently
    7.27 +load balancing runnable VCPUs across the whole system.
    7.28  
    7.29  \paragraph*{Note: SMP host support}
    7.30 -Xen has always supported SMP host systems.  Domains are statically
    7.31 -assigned to CPUs, either at creation time or when manually pinning to
    7.32 -a particular CPU.  The current schedulers then run locally on each CPU
    7.33 -to decide which of the assigned domains should be run there. The
    7.34 -user-level control software can be used to perform coarse-grain
    7.35 -load-balancing between CPUs.
    7.36 -\end{comment}
    7.37 +Xen has always supported SMP host systems. When using the credit scheduler,
    7.38 +a domain's VCPUs will be dynamically moved across physical CPUs to maximise
    7.39 +domain and system throughput. VCPUs can also be manually restricted to be
    7.40 +mapped only on a subset of the host's physical CPUs, using the pinning
    7.41 +mechanism.
    7.42  
    7.43  
    7.44  %% More information on the characteristics and use of these schedulers
     8.1 --- a/docs/src/user.tex	Wed May 31 11:30:07 2006 -0600
     8.2 +++ b/docs/src/user.tex	Wed May 31 13:05:21 2006 -0600
     8.3 @@ -1094,6 +1094,36 @@ running domains in \xend's SXP configura
     8.4  You can get access to the console of a particular domain using 
     8.5  the \verb_# xm console_ command  (e.g.\ \verb_# xm console myVM_). 
     8.6  
     8.7 +\subsection{Domain Scheduling Management Commands}
     8.8 +
     8.9 +The credit CPU scheduler automatically load balances guest VCPUs
    8.10 +across all available physical CPUs on an SMP host. The user need
    8.11 +not manually pin VCPUs to load balance the system. However, she
    8.12 +can restrict which CPUs a particular VCPU may run on using
    8.13 +the \path{xm vcpu-pin} command.
    8.14 +
    8.15 +Each guest domain is assigned a \path{weight} and a \path{cap}.
    8.16 +
    8.17 +A domain with a weight of 512 will get twice as much CPU as a
    8.18 +domain with a weight of 256 on a contended host. Legal weights
    8.19 +range from 1 to 65535 and the default is 256.
    8.20 +
    8.21 +The cap optionally fixes the maximum amount of CPU a guest will
    8.22 +be able to consume, even if the host system has idle CPU cycles.
    8.23 +The cap is expressed in percentage of one physical CPU: 100 is
    8.24 +1 physical CPU, 50 is half a CPU, 400 is 4 CPUs, etc... The
    8.25 +default, 0, means there is no upper cap.
    8.26 +
    8.27 +When you are running with the credit scheduler, you can check and
    8.28 +modify your domains' weights and caps using the \path{xm sched-credit}
    8.29 +command:
    8.30 +
    8.31 +\begin{tabular}{ll}
    8.32 +\verb!xm sched-credit -d <domain>! & lists weight and cap \\
    8.33 +\verb!xm sched-credit -d <domain> -w <weight>! & sets the weight \\
    8.34 +\verb!xm sched-credit -d <domain> -c <cap>! & sets the cap
    8.35 +\end{tabular}
    8.36 +
    8.37  
    8.38  
    8.39  %% Chapter Domain Configuration
    8.40 @@ -1985,7 +2015,7 @@ editing \path{grub.conf}.
    8.41  \item [ tbuf\_size=xxx ] Set the size of the per-cpu trace buffers, in
    8.42    pages (default 0).  
    8.43  \item [ sched=xxx ] Select the CPU scheduler Xen should use.  The
    8.44 -  current possibilities are `sedf' (default) and `bvt'.
    8.45 +  current possibilities are `sedf' (default), `credit', and `bvt'.
    8.46  \item [ apic\_verbosity=debug,verbose ] Print more detailed
    8.47    information about local APIC and IOAPIC configuration.
    8.48  \item [ lapic ] Force use of local APIC even when left disabled by
     9.1 --- a/extras/mini-os/Makefile	Wed May 31 11:30:07 2006 -0600
     9.2 +++ b/extras/mini-os/Makefile	Wed May 31 13:05:21 2006 -0600
     9.3 @@ -1,7 +1,8 @@
     9.4  debug ?= y
     9.5  pae ?= n
     9.6  
     9.7 -include $(CURDIR)/../../Config.mk
     9.8 +XEN_ROOT = ../..
     9.9 +include $(XEN_ROOT)/Config.mk
    9.10  
    9.11  # Set TARGET_ARCH
    9.12  override TARGET_ARCH     := $(XEN_TARGET_ARCH)
    10.1 --- a/extras/mini-os/include/mm.h	Wed May 31 11:30:07 2006 -0600
    10.2 +++ b/extras/mini-os/include/mm.h	Wed May 31 13:05:21 2006 -0600
    10.3 @@ -53,7 +53,7 @@
    10.4  #define PADDR_BITS              32
    10.5  #define PADDR_MASK              (~0UL)
    10.6  
    10.7 -#define UNMAPPED_PT_FRAMES        1
    10.8 +#define NOT_L1_FRAMES           1
    10.9  #define PRIpte "08lx"
   10.10  typedef unsigned long pgentry_t;
   10.11  
   10.12 @@ -71,7 +71,12 @@ typedef unsigned long pgentry_t;
   10.13  
   10.14  #define L2_MASK  ((1UL << L3_PAGETABLE_SHIFT) - 1)
   10.15  
   10.16 -#define UNMAPPED_PT_FRAMES        2
   10.17 +/*
   10.18 + * If starting from virtual address greater than 0xc0000000,
   10.19 + * this value will be 2 to account for final mid-level page
   10.20 + * directory which is always mapped in at this location.
   10.21 + */
   10.22 +#define NOT_L1_FRAMES           3
   10.23  #define PRIpte "016llx"
   10.24  typedef uint64_t pgentry_t;
   10.25  
   10.26 @@ -94,20 +99,10 @@ typedef uint64_t pgentry_t;
   10.27  #define PADDR_MASK              ((1UL << PADDR_BITS)-1)
   10.28  #define VADDR_MASK              ((1UL << VADDR_BITS)-1)
   10.29  
   10.30 -/* Get physical address of page mapped by pte (paddr_t). */
   10.31 -#define l1e_get_paddr(x)           \
   10.32 -    ((unsigned long)(((x) & (PADDR_MASK&PAGE_MASK))))
   10.33 -#define l2e_get_paddr(x)           \
   10.34 -    ((unsigned long)(((x) & (PADDR_MASK&PAGE_MASK))))
   10.35 -#define l3e_get_paddr(x)           \
   10.36 -    ((unsigned long)(((x) & (PADDR_MASK&PAGE_MASK))))
   10.37 -#define l4e_get_paddr(x)           \
   10.38 -    ((unsigned long)(((x) & (PADDR_MASK&PAGE_MASK))))
   10.39 -
   10.40  #define L2_MASK  ((1UL << L3_PAGETABLE_SHIFT) - 1)
   10.41  #define L3_MASK  ((1UL << L4_PAGETABLE_SHIFT) - 1)
   10.42  
   10.43 -#define UNMAPPED_PT_FRAMES        3
   10.44 +#define NOT_L1_FRAMES           3
   10.45  #define PRIpte "016lx"
   10.46  typedef unsigned long pgentry_t;
   10.47  
    11.1 --- a/extras/mini-os/minios-x86_32.lds	Wed May 31 11:30:07 2006 -0600
    11.2 +++ b/extras/mini-os/minios-x86_32.lds	Wed May 31 13:05:21 2006 -0600
    11.3 @@ -3,7 +3,7 @@ OUTPUT_ARCH(i386)
    11.4  ENTRY(_start)
    11.5  SECTIONS
    11.6  {
    11.7 -  . = 0xC0000000;
    11.8 +  . = 0x0;
    11.9    _text = .;			/* Text and read-only data */
   11.10    .text : {
   11.11  	*(.text)
    12.1 --- a/extras/mini-os/minios-x86_64.lds	Wed May 31 11:30:07 2006 -0600
    12.2 +++ b/extras/mini-os/minios-x86_64.lds	Wed May 31 13:05:21 2006 -0600
    12.3 @@ -3,7 +3,7 @@ OUTPUT_ARCH(i386:x86-64)
    12.4  ENTRY(_start)
    12.5  SECTIONS
    12.6  {
    12.7 -  . = 0xFFFFFFFF80000000;
    12.8 +  . = 0x0;
    12.9    _text = .;			/* Text and read-only data */
   12.10    .text : {
   12.11  	*(.text)
    13.1 --- a/extras/mini-os/mm.c	Wed May 31 11:30:07 2006 -0600
    13.2 +++ b/extras/mini-os/mm.c	Wed May 31 13:05:21 2006 -0600
    13.3 @@ -375,7 +375,7 @@ void new_pt_frame(unsigned long *pt_pfn,
    13.4      struct mmuext_op pin_request;
    13.5      
    13.6      DEBUG("Allocating new L%d pt frame for pt_pfn=%lx, "
    13.7 -           "prev_l_mfn=%lx, offset=%lx\n", 
    13.8 +           "prev_l_mfn=%lx, offset=%lx", 
    13.9             level, *pt_pfn, prev_l_mfn, offset);
   13.10  
   13.11      /* We need to clear the page, otherwise we might fail to map it
   13.12 @@ -442,7 +442,7 @@ void new_pt_frame(unsigned long *pt_pfn,
   13.13      mmu_updates[0].ptr = ((pgentry_t)prev_l_mfn << PAGE_SHIFT) + sizeof(pgentry_t) * offset;
   13.14      mmu_updates[0].val = (pgentry_t)pfn_to_mfn(*pt_pfn) << PAGE_SHIFT | prot_t;
   13.15      if(HYPERVISOR_mmu_update(mmu_updates, 1, NULL, DOMID_SELF) < 0) 
   13.16 -    {            
   13.17 +    {
   13.18         printk("ERROR: mmu_update failed\n");
   13.19         do_exit();
   13.20      }
   13.21 @@ -450,6 +450,58 @@ void new_pt_frame(unsigned long *pt_pfn,
   13.22      *pt_pfn += 1;
   13.23  }
   13.24  
   13.25 +/* Checks if a pagetable frame is needed (if weren't allocated by Xen) */
   13.26 +static int need_pt_frame(unsigned long virt_address, int level)
   13.27 +{
   13.28 +    unsigned long hyp_virt_start = HYPERVISOR_VIRT_START;
   13.29 +#if defined(__x86_64__)
   13.30 +    unsigned long hyp_virt_end = HYPERVISOR_VIRT_END;
   13.31 +#else
   13.32 +    unsigned long hyp_virt_end = 0xffffffff;
   13.33 +#endif
   13.34 +
   13.35 +    /* In general frames will _not_ be needed if they were already
   13.36 +       allocated to map the hypervisor into our VA space */
   13.37 +#if defined(__x86_64__)
   13.38 +    if(level == L3_FRAME)
   13.39 +    {
   13.40 +        if(l4_table_offset(virt_address) >= 
   13.41 +           l4_table_offset(hyp_virt_start) &&
   13.42 +           l4_table_offset(virt_address) <= 
   13.43 +           l4_table_offset(hyp_virt_end))
   13.44 +            return 0;
   13.45 +        return 1;
   13.46 +    } else
   13.47 +#endif
   13.48 +
   13.49 +#if defined(__x86_64__) || defined(CONFIG_X86_PAE)
   13.50 +    if(level == L2_FRAME)
   13.51 +    {
   13.52 +#if defined(__x86_64__)
   13.53 +        if(l4_table_offset(virt_address) >= 
   13.54 +           l4_table_offset(hyp_virt_start) &&
   13.55 +           l4_table_offset(virt_address) <= 
   13.56 +           l4_table_offset(hyp_virt_end))
   13.57 +#endif
   13.58 +            if(l3_table_offset(virt_address) >= 
   13.59 +               l3_table_offset(hyp_virt_start) &&
   13.60 +               l3_table_offset(virt_address) <= 
   13.61 +               l3_table_offset(hyp_virt_end))
   13.62 +                return 0;
   13.63 +
   13.64 +        return 1;
   13.65 +    } else 
   13.66 +#endif /* defined(__x86_64__) || defined(CONFIG_X86_PAE) */
   13.67 +
   13.68 +    /* Always need l1 frames */
   13.69 +    if(level == L1_FRAME)
   13.70 +        return 1;
   13.71 +
   13.72 +    printk("ERROR: Unknown frame level %d, hypervisor %llx,%llx\n", 
   13.73 +        level, hyp_virt_start, hyp_virt_end);
   13.74 +    return -1;
   13.75 +}
   13.76 +
   13.77  void build_pagetable(unsigned long *start_pfn, unsigned long *max_pfn)
   13.78  {
   13.79      unsigned long start_address, end_address;
   13.80 @@ -460,11 +512,21 @@ void build_pagetable(unsigned long *star
   13.81      unsigned long offset;
   13.82      int count = 0;
   13.83  
   13.84 -    pfn_to_map = (start_info.nr_pt_frames - UNMAPPED_PT_FRAMES) * L1_PAGETABLE_ENTRIES;
   13.85 +    pfn_to_map = (start_info.nr_pt_frames - NOT_L1_FRAMES) * L1_PAGETABLE_ENTRIES;
   13.86 +
   13.87 +    if (*max_pfn >= virt_to_pfn(HYPERVISOR_VIRT_START))
   13.88 +    {
   13.89 +        printk("WARNING: Mini-OS trying to use Xen virtual space. "
   13.90 +               "Truncating memory from %dMB to ",
   13.91 +               ((unsigned long)pfn_to_virt(*max_pfn) - (unsigned long)&_text)>>20);
   13.92 +        *max_pfn = virt_to_pfn(HYPERVISOR_VIRT_START - PAGE_SIZE);
   13.93 +        printk("%dMB\n",
   13.94 +               ((unsigned long)pfn_to_virt(*max_pfn) - (unsigned long)&_text)>>20);
   13.95 +    }
   13.96  
   13.97      start_address = (unsigned long)pfn_to_virt(pfn_to_map);
   13.98      end_address = (unsigned long)pfn_to_virt(*max_pfn);
   13.99 -    
  13.100 +
  13.101      /* We worked out the virtual memory range to map, now mapping loop */
  13.102      printk("Mapping memory range 0x%lx - 0x%lx\n", start_address, end_address);
  13.103  
  13.104 @@ -477,8 +539,9 @@ void build_pagetable(unsigned long *star
  13.105          offset = l4_table_offset(start_address);
  13.106          /* Need new L3 pt frame */
  13.107          if(!(start_address & L3_MASK)) 
  13.108 -            new_pt_frame(&pt_pfn, mfn, offset, L3_FRAME);
  13.109 -        
  13.110 +            if(need_pt_frame(start_address, L3_FRAME)) 
  13.111 +                new_pt_frame(&pt_pfn, mfn, offset, L3_FRAME);
  13.112 +
  13.113          page = tab[offset];
  13.114          mfn = pte_to_mfn(page);
  13.115          tab = to_virt(mfn_to_pfn(mfn) << PAGE_SHIFT);
  13.116 @@ -486,8 +549,9 @@ void build_pagetable(unsigned long *star
  13.117  #if defined(__x86_64__) || defined(CONFIG_X86_PAE)
  13.118          offset = l3_table_offset(start_address);
  13.119          /* Need new L2 pt frame */
  13.120 -        if(!(start_address & L2_MASK)) 
  13.121 -            new_pt_frame(&pt_pfn, mfn, offset, L2_FRAME);
  13.122 +        if(!(start_address & L2_MASK))
  13.123 +            if(need_pt_frame(start_address, L2_FRAME))
  13.124 +                new_pt_frame(&pt_pfn, mfn, offset, L2_FRAME);
  13.125  
  13.126          page = tab[offset];
  13.127          mfn = pte_to_mfn(page);
  13.128 @@ -495,16 +559,16 @@ void build_pagetable(unsigned long *star
  13.129  #endif
  13.130          offset = l2_table_offset(start_address);        
  13.131          /* Need new L1 pt frame */
  13.132 -        if(!(start_address & L1_MASK)) 
  13.133 -            new_pt_frame(&pt_pfn, mfn, offset, L1_FRAME);
  13.134 -       
  13.135 +        if(!(start_address & L1_MASK))
  13.136 +            if(need_pt_frame(start_address, L1_FRAME)) 
  13.137 +                new_pt_frame(&pt_pfn, mfn, offset, L1_FRAME);
  13.138 +
  13.139          page = tab[offset];
  13.140          mfn = pte_to_mfn(page);
  13.141          offset = l1_table_offset(start_address);
  13.142  
  13.143          mmu_updates[count].ptr = ((pgentry_t)mfn << PAGE_SHIFT) + sizeof(pgentry_t) * offset;
  13.144 -        mmu_updates[count].val = 
  13.145 -            (pgentry_t)pfn_to_mfn(pfn_to_map++) << PAGE_SHIFT | L1_PROT;
  13.146 +        mmu_updates[count].val = (pgentry_t)pfn_to_mfn(pfn_to_map++) << PAGE_SHIFT | L1_PROT;
  13.147          count++;
  13.148          if (count == L1_PAGETABLE_ENTRIES || pfn_to_map == *max_pfn)
  13.149          {
    14.1 --- a/extras/mini-os/x86_32.S	Wed May 31 11:30:07 2006 -0600
    14.2 +++ b/extras/mini-os/x86_32.S	Wed May 31 13:05:21 2006 -0600
    14.3 @@ -4,8 +4,8 @@
    14.4  .section __xen_guest
    14.5  	.ascii	"GUEST_OS=Mini-OS"
    14.6  	.ascii	",XEN_VER=xen-3.0"
    14.7 -	.ascii	",VIRT_BASE=0xc0000000" /* &_text from minios_x86_32.lds */
    14.8 -	.ascii	",ELF_PADDR_OFFSET=0xc0000000"
    14.9 +	.ascii	",VIRT_BASE=0x0" /* &_text from minios_x86_32.lds */
   14.10 +	.ascii	",ELF_PADDR_OFFSET=0x0"
   14.11  	.ascii	",HYPERCALL_PAGE=0x2"
   14.12  #ifdef CONFIG_X86_PAE
   14.13  	.ascii	",PAE=yes"
    15.1 --- a/extras/mini-os/x86_64.S	Wed May 31 11:30:07 2006 -0600
    15.2 +++ b/extras/mini-os/x86_64.S	Wed May 31 13:05:21 2006 -0600
    15.3 @@ -4,8 +4,8 @@
    15.4  .section __xen_guest
    15.5  	.ascii	"GUEST_OS=Mini-OS"
    15.6  	.ascii	",XEN_VER=xen-3.0"
    15.7 -	.ascii	",VIRT_BASE=0xffffffff80000000" /* &_text from minios_x86_64.lds */
    15.8 -	.ascii	",ELF_PADDR_OFFSET=0xffffffff80000000"
    15.9 +	.ascii	",VIRT_BASE=0x0" /* &_text from minios_x86_64.lds */
   15.10 +	.ascii	",ELF_PADDR_OFFSET=0x0"
   15.11  	.ascii	",HYPERCALL_PAGE=0x2"
   15.12  	.ascii	",LOADER=generic"
   15.13  	.byte	0
    16.1 --- a/linux-2.6-xen-sparse/arch/i386/kernel/process-xen.c	Wed May 31 11:30:07 2006 -0600
    16.2 +++ b/linux-2.6-xen-sparse/arch/i386/kernel/process-xen.c	Wed May 31 13:05:21 2006 -0600
    16.3 @@ -55,6 +55,7 @@
    16.4  
    16.5  #include <xen/interface/physdev.h>
    16.6  #include <xen/interface/vcpu.h>
    16.7 +#include <xen/cpu_hotplug.h>
    16.8  
    16.9  #include <linux/err.h>
   16.10  
   16.11 @@ -101,8 +102,6 @@ void enable_hlt(void)
   16.12  EXPORT_SYMBOL(enable_hlt);
   16.13  
   16.14  /* XXX XEN doesn't use default_idle(), poll_idle(). Use xen_idle() instead. */
   16.15 -extern void stop_hz_timer(void);
   16.16 -extern void start_hz_timer(void);
   16.17  void xen_idle(void)
   16.18  {
   16.19  	local_irq_disable();
   16.20 @@ -112,10 +111,7 @@ void xen_idle(void)
   16.21  	else {
   16.22  		clear_thread_flag(TIF_POLLING_NRFLAG);
   16.23  		smp_mb__after_clear_bit();
   16.24 -		stop_hz_timer();
   16.25 -		/* Blocking includes an implicit local_irq_enable(). */
   16.26 -		HYPERVISOR_block();
   16.27 -		start_hz_timer();
   16.28 +		safe_halt();
   16.29  		set_thread_flag(TIF_POLLING_NRFLAG);
   16.30  	}
   16.31  }
   16.32 @@ -132,11 +128,7 @@ static inline void play_dead(void)
   16.33  	cpu_clear(smp_processor_id(), cpu_initialized);
   16.34  	preempt_enable_no_resched();
   16.35  	HYPERVISOR_vcpu_op(VCPUOP_down, smp_processor_id(), NULL);
   16.36 -	/* Same as drivers/xen/core/smpboot.c:cpu_bringup(). */
   16.37 -	cpu_init();
   16.38 -	touch_softlockup_watchdog();
   16.39 -	preempt_disable();
   16.40 -	local_irq_enable();
   16.41 +	cpu_bringup();
   16.42  }
   16.43  #else
   16.44  static inline void play_dead(void)
    17.1 --- a/linux-2.6-xen-sparse/arch/i386/kernel/time-xen.c	Wed May 31 11:30:07 2006 -0600
    17.2 +++ b/linux-2.6-xen-sparse/arch/i386/kernel/time-xen.c	Wed May 31 13:05:21 2006 -0600
    17.3 @@ -973,7 +973,7 @@ EXPORT_SYMBOL(jiffies_to_st);
    17.4   * stop_hz_timer / start_hz_timer - enter/exit 'tickless mode' on an idle cpu
    17.5   * These functions are based on implementations from arch/s390/kernel/time.c
    17.6   */
    17.7 -void stop_hz_timer(void)
    17.8 +static void stop_hz_timer(void)
    17.9  {
   17.10  	unsigned int cpu = smp_processor_id();
   17.11  	unsigned long j;
   17.12 @@ -993,11 +993,27 @@ void stop_hz_timer(void)
   17.13  	BUG_ON(HYPERVISOR_set_timer_op(jiffies_to_st(j)) != 0);
   17.14  }
   17.15  
   17.16 -void start_hz_timer(void)
   17.17 +static void start_hz_timer(void)
   17.18  {
   17.19  	cpu_clear(smp_processor_id(), nohz_cpu_mask);
   17.20  }
   17.21  
   17.22 +void safe_halt(void)
   17.23 +{
   17.24 +	stop_hz_timer();
   17.25 +	/* Blocking includes an implicit local_irq_enable(). */
   17.26 +	HYPERVISOR_block();
   17.27 +	start_hz_timer();
   17.28 +}
   17.29 +EXPORT_SYMBOL(safe_halt);
   17.30 +
   17.31 +void halt(void)
   17.32 +{
   17.33 +	if (irqs_disabled())
   17.34 +		HYPERVISOR_vcpu_op(VCPUOP_down, smp_processor_id(), NULL);
   17.35 +}
   17.36 +EXPORT_SYMBOL(halt);
   17.37 +
   17.38  /* No locking required. We are only CPU running, and interrupts are off. */
   17.39  void time_resume(void)
   17.40  {
    18.1 --- a/linux-2.6-xen-sparse/arch/x86_64/kernel/process-xen.c	Wed May 31 11:30:07 2006 -0600
    18.2 +++ b/linux-2.6-xen-sparse/arch/x86_64/kernel/process-xen.c	Wed May 31 13:05:21 2006 -0600
    18.3 @@ -60,6 +60,8 @@
    18.4  #include <asm/ia32.h>
    18.5  #include <asm/idle.h>
    18.6  
    18.7 +#include <xen/cpu_hotplug.h>
    18.8 +
    18.9  asmlinkage extern void ret_from_fork(void);
   18.10  
   18.11  unsigned long kernel_thread_flags = CLONE_VM | CLONE_UNTRACED;
   18.12 @@ -118,8 +120,6 @@ void exit_idle(void)
   18.13  }
   18.14  
   18.15  /* XXX XEN doesn't use default_idle(), poll_idle(). Use xen_idle() instead. */
   18.16 -extern void stop_hz_timer(void);
   18.17 -extern void start_hz_timer(void);
   18.18  void xen_idle(void)
   18.19  {
   18.20  	local_irq_disable();
   18.21 @@ -129,10 +129,7 @@ void xen_idle(void)
   18.22  	else {
   18.23  		clear_thread_flag(TIF_POLLING_NRFLAG);
   18.24  		smp_mb__after_clear_bit();
   18.25 -		stop_hz_timer();
   18.26 -		/* Blocking includes an implicit local_irq_enable(). */
   18.27 -		HYPERVISOR_block();
   18.28 -		start_hz_timer();
   18.29 +		safe_halt();
   18.30  		set_thread_flag(TIF_POLLING_NRFLAG);
   18.31  	}
   18.32  }
   18.33 @@ -145,11 +142,7 @@ static inline void play_dead(void)
   18.34  	cpu_clear(smp_processor_id(), cpu_initialized);
   18.35  	preempt_enable_no_resched();
   18.36  	HYPERVISOR_vcpu_op(VCPUOP_down, smp_processor_id(), NULL);
   18.37 -	/* Same as drivers/xen/core/smpboot.c:cpu_bringup(). */
   18.38 -	cpu_init();
   18.39 -	touch_softlockup_watchdog();
   18.40 -	preempt_disable();
   18.41 -	local_irq_enable();
   18.42 +	cpu_bringup();
   18.43  }
   18.44  #else
   18.45  static inline void play_dead(void)
    19.1 --- a/linux-2.6-xen-sparse/drivers/xen/balloon/balloon.c	Wed May 31 11:30:07 2006 -0600
    19.2 +++ b/linux-2.6-xen-sparse/drivers/xen/balloon/balloon.c	Wed May 31 13:05:21 2006 -0600
    19.3 @@ -360,12 +360,6 @@ static void balloon_process(void *unused
    19.4  /* Resets the Xen limit, sets new target, and kicks off processing. */
    19.5  static void set_new_target(unsigned long target)
    19.6  {
    19.7 -	unsigned long min_target;
    19.8 -
    19.9 -	/* Do not allow target to reduce below 2% of maximum memory size. */
   19.10 -	min_target = max_pfn / 50;
   19.11 -	target = max(target, min_target);
   19.12 -
   19.13  	/* No need for lock. Not read-modify-write updates. */
   19.14  	hard_limit   = ~0UL;
   19.15  	target_pages = target;
    20.1 --- a/linux-2.6-xen-sparse/drivers/xen/core/cpu_hotplug.c	Wed May 31 11:30:07 2006 -0600
    20.2 +++ b/linux-2.6-xen-sparse/drivers/xen/core/cpu_hotplug.c	Wed May 31 13:05:21 2006 -0600
    20.3 @@ -160,7 +160,7 @@ void smp_resume(void)
    20.4  		vcpu_hotplug(cpu);
    20.5  }
    20.6  
    20.7 -int cpu_up_is_allowed(unsigned int cpu)
    20.8 +int cpu_up_check(unsigned int cpu)
    20.9  {
   20.10  	int rc = 0;
   20.11  
    21.1 --- a/linux-2.6-xen-sparse/drivers/xen/core/smpboot.c	Wed May 31 11:30:07 2006 -0600
    21.2 +++ b/linux-2.6-xen-sparse/drivers/xen/core/smpboot.c	Wed May 31 13:05:21 2006 -0600
    21.3 @@ -150,12 +150,17 @@ static void xen_smp_intr_exit(unsigned i
    21.4  }
    21.5  #endif
    21.6  
    21.7 -static void cpu_bringup(void)
    21.8 +void cpu_bringup(void)
    21.9  {
   21.10  	cpu_init();
   21.11  	touch_softlockup_watchdog();
   21.12  	preempt_disable();
   21.13  	local_irq_enable();
   21.14 +}
   21.15 +
   21.16 +static void cpu_bringup_and_idle(void)
   21.17 +{
   21.18 +	cpu_bringup();
   21.19  	cpu_idle();
   21.20  }
   21.21  
   21.22 @@ -180,7 +185,7 @@ void cpu_initialize_context(unsigned int
   21.23  	ctxt.user_regs.fs = 0;
   21.24  	ctxt.user_regs.gs = 0;
   21.25  	ctxt.user_regs.ss = __KERNEL_DS;
   21.26 -	ctxt.user_regs.eip = (unsigned long)cpu_bringup;
   21.27 +	ctxt.user_regs.eip = (unsigned long)cpu_bringup_and_idle;
   21.28  	ctxt.user_regs.eflags = X86_EFLAGS_IF | 0x1000; /* IOPL_RING1 */
   21.29  
   21.30  	memset(&ctxt.fpu_ctxt, 0, sizeof(ctxt.fpu_ctxt));
   21.31 @@ -400,7 +405,7 @@ int __devinit __cpu_up(unsigned int cpu)
   21.32  {
   21.33  	int rc;
   21.34  
   21.35 -	rc = cpu_up_is_allowed(cpu);
   21.36 +	rc = cpu_up_check(cpu);
   21.37  	if (rc)
   21.38  		return rc;
   21.39  
    22.1 --- a/linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/dma-mapping.h	Wed May 31 11:30:07 2006 -0600
    22.2 +++ b/linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/dma-mapping.h	Wed May 31 13:05:21 2006 -0600
    22.3 @@ -128,8 +128,6 @@ dma_get_cache_alignment(void)
    22.4  	 * maximum possible, to be safe */
    22.5  	return (1 << INTERNODE_CACHE_SHIFT);
    22.6  }
    22.7 -#else
    22.8 -extern int dma_get_cache_alignment(void);
    22.9  #endif
   22.10  
   22.11  #define dma_is_consistent(d)	(1)
    23.1 --- a/linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/hypercall.h	Wed May 31 11:30:07 2006 -0600
    23.2 +++ b/linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/hypercall.h	Wed May 31 13:05:21 2006 -0600
    23.3 @@ -260,6 +260,13 @@ HYPERVISOR_event_channel_op(
    23.4  }
    23.5  
    23.6  static inline int
    23.7 +HYPERVISOR_acm_op(
    23.8 +	int cmd, void *arg)
    23.9 +{
   23.10 +	return _hypercall2(int, acm_op, cmd, arg);
   23.11 +}
   23.12 +
   23.13 +static inline int
   23.14  HYPERVISOR_xen_version(
   23.15  	int cmd, void *arg)
   23.16  {
    24.1 --- a/linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/system.h	Wed May 31 11:30:07 2006 -0600
    24.2 +++ b/linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/system.h	Wed May 31 13:05:21 2006 -0600
    24.3 @@ -625,8 +625,8 @@ do {									\
    24.4  		preempt_enable_no_resched();				\
    24.5  } while (0)
    24.6  
    24.7 -#define safe_halt()		((void)0)
    24.8 -#define halt()			((void)0)
    24.9 +void safe_halt(void);
   24.10 +void halt(void);
   24.11  
   24.12  #define __save_and_cli(x)						\
   24.13  do {									\
    25.1 --- a/linux-2.6-xen-sparse/include/asm-ia64/hypercall.h	Wed May 31 11:30:07 2006 -0600
    25.2 +++ b/linux-2.6-xen-sparse/include/asm-ia64/hypercall.h	Wed May 31 13:05:21 2006 -0600
    25.3 @@ -247,6 +247,13 @@ HYPERVISOR_event_channel_op(
    25.4  }
    25.5  
    25.6  static inline int
    25.7 +HYPERVISOR_acm_op(
    25.8 +	unsigned int cmd, void *arg)
    25.9 +{
   25.10 +    return _hypercall2(int, acm_op, cmd, arg);
   25.11 +}
   25.12 +
   25.13 +static inline int
   25.14  HYPERVISOR_xen_version(
   25.15      int cmd, void *arg)
   25.16  {
    26.1 --- a/linux-2.6-xen-sparse/include/asm-x86_64/mach-xen/asm/hypercall.h	Wed May 31 11:30:07 2006 -0600
    26.2 +++ b/linux-2.6-xen-sparse/include/asm-x86_64/mach-xen/asm/hypercall.h	Wed May 31 13:05:21 2006 -0600
    26.3 @@ -258,6 +258,13 @@ HYPERVISOR_event_channel_op(
    26.4  }
    26.5  
    26.6  static inline int
    26.7 +HYPERVISOR_acm_op(
    26.8 +	int cmd, void *arg)
    26.9 +{
   26.10 +	return _hypercall2(int, acm_op, cmd, arg);
   26.11 +}
   26.12 +
   26.13 +static inline int
   26.14  HYPERVISOR_xen_version(
   26.15  	int cmd, void *arg)
   26.16  {
    27.1 --- a/linux-2.6-xen-sparse/include/asm-x86_64/mach-xen/asm/system.h	Wed May 31 11:30:07 2006 -0600
    27.2 +++ b/linux-2.6-xen-sparse/include/asm-x86_64/mach-xen/asm/system.h	Wed May 31 13:05:21 2006 -0600
    27.3 @@ -424,8 +424,8 @@ do {									\
    27.4  	preempt_enable_no_resched();					\
    27.5  	___x; })
    27.6  
    27.7 -#define safe_halt()		((void)0)
    27.8 -#define halt()			((void)0)
    27.9 +void safe_halt(void);
   27.10 +void halt(void);
   27.11  
   27.12  void cpu_idle_wait(void);
   27.13  
    28.1 --- a/linux-2.6-xen-sparse/include/xen/cpu_hotplug.h	Wed May 31 11:30:07 2006 -0600
    28.2 +++ b/linux-2.6-xen-sparse/include/xen/cpu_hotplug.h	Wed May 31 13:05:21 2006 -0600
    28.3 @@ -13,14 +13,16 @@ void cpu_initialize_context(unsigned int
    28.4  #define cpu_initialize_context(cpu)	((void)0)
    28.5  #endif
    28.6  
    28.7 -int cpu_up_is_allowed(unsigned int cpu);
    28.8 +int cpu_up_check(unsigned int cpu);
    28.9  void init_xenbus_allowed_cpumask(void);
   28.10  int smp_suspend(void);
   28.11  void smp_resume(void);
   28.12  
   28.13 +void cpu_bringup(void);
   28.14 +
   28.15  #else /* !defined(CONFIG_HOTPLUG_CPU) */
   28.16  
   28.17 -#define cpu_up_is_allowed(cpu)		(1)
   28.18 +#define cpu_up_check(cpu)		(0)
   28.19  #define init_xenbus_allowed_cpumask()	((void)0)
   28.20  
   28.21  static inline int smp_suspend(void)
    29.1 --- a/tools/Makefile	Wed May 31 11:30:07 2006 -0600
    29.2 +++ b/tools/Makefile	Wed May 31 13:05:21 2006 -0600
    29.3 @@ -1,39 +1,38 @@
    29.4  XEN_ROOT = ../
    29.5  include $(XEN_ROOT)/tools/Rules.mk
    29.6  
    29.7 -SUBDIRS :=
    29.8 -SUBDIRS += libxc
    29.9 -SUBDIRS += xenstore
   29.10 -SUBDIRS += misc
   29.11 -SUBDIRS += examples
   29.12 -SUBDIRS += xentrace
   29.13 -SUBDIRS += xcutils
   29.14 -SUBDIRS += firmware
   29.15 -SUBDIRS += security
   29.16 -SUBDIRS += console
   29.17 -SUBDIRS += xenmon
   29.18 -SUBDIRS += guest-headers
   29.19 -ifeq ($(VTPM_TOOLS),y)
   29.20 -SUBDIRS += vtpm_manager
   29.21 -SUBDIRS += vtpm
   29.22 -endif
   29.23 -SUBDIRS += xenstat
   29.24 +SUBDIRS-y :=
   29.25 +SUBDIRS-y += libxc
   29.26 +SUBDIRS-y += xenstore
   29.27 +SUBDIRS-y += misc
   29.28 +SUBDIRS-y += examples
   29.29 +SUBDIRS-y += xentrace
   29.30 +SUBDIRS-$(CONFIG_X86) += xcutils
   29.31 +SUBDIRS-y += firmware
   29.32 +SUBDIRS-y += security
   29.33 +SUBDIRS-y += console
   29.34 +SUBDIRS-y += xenmon
   29.35 +SUBDIRS-y += guest-headers
   29.36 +SUBDIRS-$(VTPM_TOOLS) += vtpm_manager
   29.37 +SUBDIRS-$(VTPM_TOOLS) += vtpm
   29.38 +SUBDIRS-y += xenstat
   29.39 +
   29.40  # These don't cross-compile
   29.41  ifeq ($(XEN_COMPILE_ARCH),$(XEN_TARGET_ARCH))
   29.42 -SUBDIRS += python
   29.43 -SUBDIRS += pygrub
   29.44 +SUBDIRS-y += python
   29.45 +SUBDIRS-y += pygrub
   29.46  endif
   29.47  
   29.48  .PHONY: all
   29.49  all: check
   29.50 -	@set -e; for subdir in $(SUBDIRS); do \
   29.51 +	@set -e; for subdir in $(SUBDIRS-y); do \
   29.52  		$(MAKE) -C $$subdir $@; \
   29.53  	done
   29.54  	$(MAKE) ioemu
   29.55  
   29.56  .PHONY: install
   29.57  install: check
   29.58 -	@set -e; for subdir in $(SUBDIRS); do \
   29.59 +	@set -e; for subdir in $(SUBDIRS-y); do \
   29.60  		$(MAKE) -C $$subdir $@; \
   29.61  	done
   29.62  	$(MAKE) ioemuinstall
   29.63 @@ -41,7 +40,7 @@ install: check
   29.64  
   29.65  .PHONY: clean
   29.66  clean: check_clean
   29.67 -	@set -e; for subdir in $(SUBDIRS); do \
   29.68 +	@set -e; for subdir in $(SUBDIRS-y); do \
   29.69  		$(MAKE) -C $$subdir $@; \
   29.70  	done
   29.71  	$(MAKE) ioemuclean
   29.72 @@ -55,10 +54,10 @@ check_clean:
   29.73  	$(MAKE) -C check clean
   29.74  
   29.75  .PHONY: ioemu ioemuinstall ioemuclean
   29.76 -ifndef XEN_NO_IOEMU
   29.77 +ifdef CONFIG_IOEMU
   29.78  ioemu ioemuinstall ioemuclean:
   29.79  	[ -f ioemu/config-host.h ] || \
   29.80 -	(cd ioemu; ./configure --prefix=usr)
   29.81 +	(cd ioemu; sh ./configure --prefix=usr)
   29.82  	$(MAKE) -C ioemu $(patsubst ioemu%,%,$@)
   29.83  else
   29.84  ioemu ioemuinstall ioemuclean:
    30.1 --- a/tools/Rules.mk	Wed May 31 11:30:07 2006 -0600
    30.2 +++ b/tools/Rules.mk	Wed May 31 13:05:21 2006 -0600
    30.3 @@ -5,6 +5,8 @@ all:
    30.4  
    30.5  include $(XEN_ROOT)/Config.mk
    30.6  
    30.7 +CONFIG_$(shell uname -s) := y
    30.8 +
    30.9  XEN_XC             = $(XEN_ROOT)/tools/python/xen/lowlevel/xc
   30.10  XEN_LIBXC          = $(XEN_ROOT)/tools/libxc
   30.11  XEN_XENSTORE       = $(XEN_ROOT)/tools/xenstore
    31.1 --- a/tools/firmware/hvmloader/Makefile	Wed May 31 11:30:07 2006 -0600
    31.2 +++ b/tools/firmware/hvmloader/Makefile	Wed May 31 13:05:21 2006 -0600
    31.3 @@ -51,12 +51,12 @@ hvmloader: roms.h hvmloader.c acpi_madt.
    31.4  	$(OBJCOPY) hvmloader.tmp hvmloader
    31.5  	rm -f hvmloader.tmp
    31.6  
    31.7 -roms.h:	../rombios/BIOS-bochs-latest ../vgabios/VGABIOS-lgpl-latest.bin ../vgabios/VGABIOS-lgpl-latest.cirrus.bin ../vmxassist/vmxassist.bin
    31.8 -	./mkhex rombios ../rombios/BIOS-bochs-latest > roms.h
    31.9 -	./mkhex vgabios_stdvga ../vgabios/VGABIOS-lgpl-latest.bin >> roms.h
   31.10 -	./mkhex vgabios_cirrusvga ../vgabios/VGABIOS-lgpl-latest.cirrus.bin >> roms.h
   31.11 -	./mkhex vmxassist ../vmxassist/vmxassist.bin >> roms.h
   31.12 -	./mkhex acpi ../acpi/acpi.bin >> roms.h
   31.13 +roms.h:	../rombios/BIOS-bochs-8-processors ../vgabios/VGABIOS-lgpl-latest.bin ../vgabios/VGABIOS-lgpl-latest.cirrus.bin ../vmxassist/vmxassist.bin
   31.14 +	sh ./mkhex rombios ../rombios/BIOS-bochs-8-processors > roms.h
   31.15 +	sh ./mkhex vgabios_stdvga ../vgabios/VGABIOS-lgpl-latest.bin >> roms.h
   31.16 +	sh ./mkhex vgabios_cirrusvga ../vgabios/VGABIOS-lgpl-latest.cirrus.bin >> roms.h
   31.17 +	sh ./mkhex vmxassist ../vmxassist/vmxassist.bin >> roms.h
   31.18 +	sh ./mkhex acpi ../acpi/acpi.bin >> roms.h
   31.19  
   31.20  .PHONY: clean
   31.21  clean:
    32.1 --- a/tools/firmware/rombios/Makefile	Wed May 31 11:30:07 2006 -0600
    32.2 +++ b/tools/firmware/rombios/Makefile	Wed May 31 13:05:21 2006 -0600
    32.3 @@ -1,7 +1,7 @@
    32.4 -BIOS_BUILDS = BIOS-bochs-latest
    32.5 +#BIOS_BUILDS = BIOS-bochs-latest
    32.6  #BIOS_BUILDS += BIOS-bochs-2-processors
    32.7  #BIOS_BUILDS += BIOS-bochs-4-processors
    32.8 -#BIOS_BUILDS += BIOS-bochs-8-processors
    32.9 +BIOS_BUILDS += BIOS-bochs-8-processors
   32.10  
   32.11  .PHONY: all
   32.12  all: bios
    33.1 --- a/tools/ioemu/hw/ne2000.c	Wed May 31 11:30:07 2006 -0600
    33.2 +++ b/tools/ioemu/hw/ne2000.c	Wed May 31 13:05:21 2006 -0600
    33.3 @@ -147,9 +147,33 @@ static void ne2000_reset(NE2000State *s)
    33.4      }
    33.5  }
    33.6  
    33.7 +static int ne2000_buffer_full(NE2000State *s)
    33.8 +{
    33.9 +    int avail, index, boundary;
   33.10 +
   33.11 +    index = s->curpag << 8;
   33.12 +    boundary = s->boundary << 8;
   33.13 +    if (index <= boundary)
   33.14 +        /* when index == boundary, we should assume the
   33.15 +         * buffer is full instead of empty!
   33.16 +         */
   33.17 +        avail = boundary - index;
   33.18 +    else
   33.19 +        avail = (s->stop - s->start) - (index - boundary);
   33.20 +
   33.21 +    return (avail < (MAX_ETH_FRAME_SIZE + 4));
   33.22 +}
   33.23 +
   33.24  static void ne2000_update_irq(NE2000State *s)
   33.25  {
   33.26      int isr;
   33.27 +
   33.28 +    if (ne2000_buffer_full(s)) {
   33.29 +        /* The freeing space is not enough, tell the ne2k driver
   33.30 +         * to fetch these packets!
   33.31 +         */
   33.32 +        s->isr |= ENISR_RX;
   33.33 +    }
   33.34      isr = s->isr & s->imr;
   33.35  #if defined(DEBUG_NE2000)
   33.36      printf("NE2000: Set IRQ line %d to %d (%02x %02x)\n",
   33.37 @@ -168,19 +192,11 @@ static void ne2000_update_irq(NE2000Stat
   33.38  static int ne2000_can_receive(void *opaque)
   33.39  {
   33.40      NE2000State *s = opaque;
   33.41 -    int avail, index, boundary;
   33.42      
   33.43      if (s->cmd & E8390_STOP)
   33.44          return 0;
   33.45 -    index = s->curpag << 8;
   33.46 -    boundary = s->boundary << 8;
   33.47 -    if (index < boundary)
   33.48 -        avail = boundary - index;
   33.49 -    else
   33.50 -        avail = (s->stop - s->start) - (index - boundary);
   33.51 -    if (avail < (MAX_ETH_FRAME_SIZE + 4))
   33.52 -        return 0;
   33.53 -    return MAX_ETH_FRAME_SIZE;
   33.54 +
   33.55 +    return (ne2000_buffer_full(s) ? 0 : MAX_ETH_FRAME_SIZE);
   33.56  }
   33.57  
   33.58  #define MIN_BUF_SIZE 60
    34.1 --- a/tools/libxc/Makefile	Wed May 31 11:30:07 2006 -0600
    34.2 +++ b/tools/libxc/Makefile	Wed May 31 13:05:21 2006 -0600
    34.3 @@ -10,43 +10,30 @@ MINOR    = 0
    34.4  XEN_ROOT = ../..
    34.5  include $(XEN_ROOT)/tools/Rules.mk
    34.6  
    34.7 -SRCS       :=
    34.8 -SRCS       += xc_bvtsched.c
    34.9 -SRCS       += xc_core.c
   34.10 -SRCS       += xc_domain.c
   34.11 -SRCS       += xc_evtchn.c
   34.12 -SRCS       += xc_misc.c
   34.13 -SRCS       += xc_acm.c   
   34.14 -SRCS       += xc_physdev.c
   34.15 -SRCS       += xc_private.c
   34.16 -SRCS       += xc_sedf.c
   34.17 -SRCS       += xc_csched.c
   34.18 -SRCS       += xc_tbuf.c
   34.19 -
   34.20 -ifeq ($(patsubst x86%,x86,$(XEN_TARGET_ARCH)),x86)
   34.21 -SRCS       += xc_ptrace.c
   34.22 -SRCS       += xc_ptrace_core.c
   34.23 -SRCS       += xc_pagetab.c
   34.24 -endif
   34.25 +CTRL_SRCS-y       :=
   34.26 +CTRL_SRCS-y       += xc_bvtsched.c
   34.27 +CTRL_SRCS-y       += xc_core.c
   34.28 +CTRL_SRCS-y       += xc_domain.c
   34.29 +CTRL_SRCS-y       += xc_evtchn.c
   34.30 +CTRL_SRCS-y       += xc_misc.c
   34.31 +CTRL_SRCS-y       += xc_acm.c   
   34.32 +CTRL_SRCS-y       += xc_physdev.c
   34.33 +CTRL_SRCS-y       += xc_private.c
   34.34 +CTRL_SRCS-y       += xc_sedf.c
   34.35 +CTRL_SRCS-y       += xc_csched.c
   34.36 +CTRL_SRCS-y       += xc_tbuf.c
   34.37 +CTRL_SRCS-$(CONFIG_X86) += xc_ptrace.c xc_ptrace_core.c xc_pagetab.c
   34.38 +CTRL_SRCS-$(CONFIG_Linux) += xc_linux.c
   34.39  
   34.40 -SRCS_Linux += xc_linux.c
   34.41 -
   34.42 -SRCS       += $(SRCS_Linux)
   34.43 -
   34.44 -BUILD_SRCS :=
   34.45 -BUILD_SRCS += xc_linux_build.c
   34.46 -BUILD_SRCS += xc_load_bin.c
   34.47 -BUILD_SRCS += xc_load_elf.c
   34.48 -BUILD_SRCS += xg_private.c
   34.49 -
   34.50 -ifeq ($(XEN_TARGET_ARCH),ia64)
   34.51 -BUILD_SRCS += xc_ia64_stubs.c
   34.52 -else
   34.53 -BUILD_SRCS += xc_load_aout9.c
   34.54 -BUILD_SRCS += xc_linux_restore.c
   34.55 -BUILD_SRCS += xc_linux_save.c
   34.56 -BUILD_SRCS += xc_hvm_build.c
   34.57 -endif
   34.58 +GUEST_SRCS-y :=
   34.59 +GUEST_SRCS-y += xc_linux_build.c
   34.60 +GUEST_SRCS-y += xc_load_bin.c
   34.61 +GUEST_SRCS-y += xc_load_elf.c
   34.62 +GUEST_SRCS-y += xg_private.c
   34.63 +GUEST_SRCS-$(CONFIG_IA64) += xc_ia64_stubs.c
   34.64 +GUEST_SRCS-$(CONFIG_PLAN9) += xc_load_aout9.c
   34.65 +GUEST_SRCS-$(CONFIG_MIGRATE) += xc_linux_restore.c xc_linux_save.c
   34.66 +GUEST_SRCS-$(CONFIG_HVM) += xc_hvm_build.c
   34.67  
   34.68  CFLAGS   += -Werror
   34.69  CFLAGS   += -fno-strict-aliasing
   34.70 @@ -61,11 +48,11 @@ CFLAGS   += -Wp,-MD,.$(@F).d
   34.71  LDFLAGS  += -L.
   34.72  DEPS     = .*.d
   34.73  
   34.74 -LIB_OBJS := $(patsubst %.c,%.o,$(SRCS))
   34.75 -PIC_OBJS := $(patsubst %.c,%.opic,$(SRCS))
   34.76 +CTRL_LIB_OBJS := $(patsubst %.c,%.o,$(CTRL_SRCS-y))
   34.77 +CTRL_PIC_OBJS := $(patsubst %.c,%.opic,$(CTRL_SRCS-y))
   34.78  
   34.79 -LIB_BUILD_OBJS := $(patsubst %.c,%.o,$(BUILD_SRCS))
   34.80 -PIC_BUILD_OBJS := $(patsubst %.c,%.opic,$(BUILD_SRCS))
   34.81 +GUEST_LIB_OBJS := $(patsubst %.c,%.o,$(GUEST_SRCS-y))
   34.82 +GUEST_PIC_OBJS := $(patsubst %.c,%.opic,$(GUEST_SRCS-y))
   34.83  
   34.84  LIB := libxenctrl.a
   34.85  LIB += libxenctrl.so libxenctrl.so.$(MAJOR) libxenctrl.so.$(MAJOR).$(MINOR)
   34.86 @@ -125,7 +112,7 @@ rpm: build
   34.87  
   34.88  # libxenctrl
   34.89  
   34.90 -libxenctrl.a: $(LIB_OBJS)
   34.91 +libxenctrl.a: $(CTRL_LIB_OBJS)
   34.92  	$(AR) rc $@ $^
   34.93  
   34.94  libxenctrl.so: libxenctrl.so.$(MAJOR)
   34.95 @@ -133,12 +120,12 @@ libxenctrl.so: libxenctrl.so.$(MAJOR)
   34.96  libxenctrl.so.$(MAJOR): libxenctrl.so.$(MAJOR).$(MINOR)
   34.97  	ln -sf $< $@
   34.98  
   34.99 -libxenctrl.so.$(MAJOR).$(MINOR): $(PIC_OBJS)
  34.100 +libxenctrl.so.$(MAJOR).$(MINOR): $(CTRL_PIC_OBJS)
  34.101  	$(CC) $(CFLAGS) $(LDFLAGS) -Wl,-soname -Wl,libxenctrl.so.$(MAJOR) -shared -o $@ $^
  34.102  
  34.103  # libxenguest
  34.104  
  34.105 -libxenguest.a: $(LIB_BUILD_OBJS)
  34.106 +libxenguest.a: $(GUEST_LIB_OBJS)
  34.107  	$(AR) rc $@ $^
  34.108  
  34.109  libxenguest.so: libxenguest.so.$(MAJOR)
  34.110 @@ -146,7 +133,7 @@ libxenguest.so: libxenguest.so.$(MAJOR)
  34.111  libxenguest.so.$(MAJOR): libxenguest.so.$(MAJOR).$(MINOR)
  34.112  	ln -sf $< $@
  34.113  
  34.114 -libxenguest.so.$(MAJOR).$(MINOR): $(PIC_BUILD_OBJS) libxenctrl.so
  34.115 +libxenguest.so.$(MAJOR).$(MINOR): $(GUEST_PIC_OBJS) libxenctrl.so
  34.116  	$(CC) $(CFLAGS) $(LDFLAGS) -Wl,-soname -Wl,libxenguest.so.$(MAJOR) -shared -o $@ $^ -lz -lxenctrl
  34.117  
  34.118  -include $(DEPS)
    35.1 --- a/tools/libxc/xc_core.c	Wed May 31 11:30:07 2006 -0600
    35.2 +++ b/tools/libxc/xc_core.c	Wed May 31 13:05:21 2006 -0600
    35.3 @@ -1,6 +1,4 @@
    35.4  #include "xg_private.h"
    35.5 -#define ELFSIZE 32
    35.6 -#include "xc_elf.h"
    35.7  #include <stdlib.h>
    35.8  #include <unistd.h>
    35.9  
    36.1 --- a/tools/libxc/xc_csched.c	Wed May 31 11:30:07 2006 -0600
    36.2 +++ b/tools/libxc/xc_csched.c	Wed May 31 13:05:21 2006 -0600
    36.3 @@ -12,10 +12,10 @@
    36.4  
    36.5  
    36.6  int
    36.7 -xc_csched_domain_set(
    36.8 +xc_sched_credit_domain_set(
    36.9      int xc_handle,
   36.10      uint32_t domid,
   36.11 -    struct csched_domain *sdom)
   36.12 +    struct sched_credit_adjdom *sdom)
   36.13  {
   36.14      DECLARE_DOM0_OP;
   36.15  
   36.16 @@ -29,10 +29,10 @@ xc_csched_domain_set(
   36.17  }
   36.18  
   36.19  int
   36.20 -xc_csched_domain_get(
   36.21 +xc_sched_credit_domain_get(
   36.22      int xc_handle,
   36.23      uint32_t domid,
   36.24 -    struct csched_domain *sdom)
   36.25 +    struct sched_credit_adjdom *sdom)
   36.26  {
   36.27      DECLARE_DOM0_OP;
   36.28      int err;
    37.1 --- a/tools/libxc/xc_hvm_build.c	Wed May 31 11:30:07 2006 -0600
    37.2 +++ b/tools/libxc/xc_hvm_build.c	Wed May 31 13:05:21 2006 -0600
    37.3 @@ -2,9 +2,9 @@
    37.4   * xc_hvm_build.c
    37.5   */
    37.6  
    37.7 +#define ELFSIZE 32
    37.8  #include <stddef.h>
    37.9  #include "xg_private.h"
   37.10 -#define ELFSIZE 32
   37.11  #include "xc_elf.h"
   37.12  #include <stdlib.h>
   37.13  #include <unistd.h>
    38.1 --- a/tools/libxc/xc_linux_build.c	Wed May 31 11:30:07 2006 -0600
    38.2 +++ b/tools/libxc/xc_linux_build.c	Wed May 31 13:05:21 2006 -0600
    38.3 @@ -6,14 +6,6 @@
    38.4  #include "xc_private.h"
    38.5  #include <xenctrl.h>
    38.6  
    38.7 -#if defined(__i386__)
    38.8 -#define ELFSIZE 32
    38.9 -#endif
   38.10 -
   38.11 -#if defined(__x86_64__) || defined(__ia64__)
   38.12 -#define ELFSIZE 64
   38.13 -#endif
   38.14 -
   38.15  #include "xc_elf.h"
   38.16  #include "xc_aout9.h"
   38.17  #include <stdlib.h>
    39.1 --- a/tools/libxc/xc_load_elf.c	Wed May 31 11:30:07 2006 -0600
    39.2 +++ b/tools/libxc/xc_load_elf.c	Wed May 31 13:05:21 2006 -0600
    39.3 @@ -3,14 +3,6 @@
    39.4   */
    39.5  
    39.6  #include "xg_private.h"
    39.7 -
    39.8 -#if defined(__i386__)
    39.9 -#define ELFSIZE 32
   39.10 -#endif
   39.11 -#if defined(__x86_64__) || defined(__ia64__)
   39.12 -#define ELFSIZE 64
   39.13 -#endif
   39.14 -
   39.15  #include "xc_elf.h"
   39.16  #include <stdlib.h>
   39.17  
    40.1 --- a/tools/libxc/xenctrl.h	Wed May 31 11:30:07 2006 -0600
    40.2 +++ b/tools/libxc/xenctrl.h	Wed May 31 13:05:21 2006 -0600
    40.3 @@ -354,13 +354,13 @@ int xc_sedf_domain_get(int xc_handle,
    40.4                         uint64_t *latency, uint16_t *extratime,
    40.5                         uint16_t *weight);
    40.6  
    40.7 -int xc_csched_domain_set(int xc_handle,
    40.8 -                         uint32_t domid,
    40.9 -                         struct csched_domain *sdom);
   40.10 +int xc_sched_credit_domain_set(int xc_handle,
   40.11 +                               uint32_t domid,
   40.12 +                               struct sched_credit_adjdom *sdom);
   40.13  
   40.14 -int xc_csched_domain_get(int xc_handle,
   40.15 -                         uint32_t domid,
   40.16 -                         struct csched_domain *sdom);
   40.17 +int xc_sched_credit_domain_get(int xc_handle,
   40.18 +                               uint32_t domid,
   40.19 +                               struct sched_credit_adjdom *sdom);
   40.20  
   40.21  typedef evtchn_status_t xc_evtchn_status_t;
   40.22  
    41.1 --- a/tools/libxc/xg_private.c	Wed May 31 11:30:07 2006 -0600
    41.2 +++ b/tools/libxc/xg_private.c	Wed May 31 13:05:21 2006 -0600
    41.3 @@ -145,3 +145,18 @@ unsigned long csum_page(void *page)
    41.4  
    41.5      return sum ^ (sum>>32);
    41.6  }
    41.7 +
    41.8 +__attribute__((weak)) int xc_hvm_build(
    41.9 +    int xc_handle,
   41.10 +    uint32_t domid,
   41.11 +    int memsize,
   41.12 +    const char *image_name,
   41.13 +    unsigned int vcpus,
   41.14 +    unsigned int pae,
   41.15 +    unsigned int acpi,
   41.16 +    unsigned int apic,
   41.17 +    unsigned int store_evtchn,
   41.18 +    unsigned long *store_mfn)
   41.19 +{
   41.20 +    return -ENOSYS;
   41.21 +}
    42.1 --- a/tools/libxc/xg_private.h	Wed May 31 11:30:07 2006 -0600
    42.2 +++ b/tools/libxc/xg_private.h	Wed May 31 13:05:21 2006 -0600
    42.3 @@ -25,6 +25,14 @@
    42.4  #define DECLARE_DOM0_OP dom0_op_t op
    42.5  #endif
    42.6  
    42.7 +#ifndef ELFSIZE
    42.8 +#include <limits.h>
    42.9 +#if UINT_MAX == ULONG_MAX
   42.10 +#define ELFSIZE 32
   42.11 +#else
   42.12 +#define ELFSIZE 64
   42.13 +#endif
   42.14 +#endif
   42.15  
   42.16  char *xc_read_image(const char *filename, unsigned long *size);
   42.17  char *xc_inflate_buffer(const char *in_buf,
    43.1 --- a/tools/misc/Makefile	Wed May 31 11:30:07 2006 -0600
    43.2 +++ b/tools/misc/Makefile	Wed May 31 13:05:21 2006 -0600
    43.3 @@ -25,7 +25,7 @@ all: build
    43.4  build: $(TARGETS)
    43.5  	$(MAKE) -C miniterm
    43.6  	$(MAKE) -C cpuperf
    43.7 -ifneq ($(XEN_TARGET_ARCH),ia64)
    43.8 +ifeq ($(CONFIG_MBOOTPACK),y)
    43.9  	$(MAKE) -C mbootpack
   43.10  endif
   43.11  	$(MAKE) -C lomount
    44.1 --- a/tools/python/xen/lowlevel/xc/xc.c	Wed May 31 11:30:07 2006 -0600
    44.2 +++ b/tools/python/xen/lowlevel/xc/xc.c	Wed May 31 13:05:21 2006 -0600
    44.3 @@ -716,16 +716,16 @@ static PyObject *pyxc_sedf_domain_get(Xc
    44.4                           "weight",    weight);
    44.5  }
    44.6  
    44.7 -static PyObject *pyxc_csched_domain_set(XcObject *self,
    44.8 -                                        PyObject *args,
    44.9 -                                        PyObject *kwds)
   44.10 +static PyObject *pyxc_sched_credit_domain_set(XcObject *self,
   44.11 +                                              PyObject *args,
   44.12 +                                              PyObject *kwds)
   44.13  {
   44.14      uint32_t domid;
   44.15      uint16_t weight;
   44.16      uint16_t cap;
   44.17      static char *kwd_list[] = { "dom", "weight", "cap", NULL };
   44.18      static char kwd_type[] = "I|HH";
   44.19 -    struct csched_domain sdom;
   44.20 +    struct sched_credit_adjdom sdom;
   44.21      
   44.22      weight = 0;
   44.23      cap = (uint16_t)~0U;
   44.24 @@ -736,22 +736,22 @@ static PyObject *pyxc_csched_domain_set(
   44.25      sdom.weight = weight;
   44.26      sdom.cap = cap;
   44.27  
   44.28 -    if ( xc_csched_domain_set(self->xc_handle, domid, &sdom) != 0 )
   44.29 +    if ( xc_sched_credit_domain_set(self->xc_handle, domid, &sdom) != 0 )
   44.30          return PyErr_SetFromErrno(xc_error);
   44.31  
   44.32      Py_INCREF(zero);
   44.33      return zero;
   44.34  }
   44.35  
   44.36 -static PyObject *pyxc_csched_domain_get(XcObject *self, PyObject *args)
   44.37 +static PyObject *pyxc_sched_credit_domain_get(XcObject *self, PyObject *args)
   44.38  {
   44.39      uint32_t domid;
   44.40 -    struct csched_domain sdom;
   44.41 +    struct sched_credit_adjdom sdom;
   44.42      
   44.43      if( !PyArg_ParseTuple(args, "I", &domid) )
   44.44          return NULL;
   44.45      
   44.46 -    if ( xc_csched_domain_get(self->xc_handle, domid, &sdom) != 0 )
   44.47 +    if ( xc_sched_credit_domain_get(self->xc_handle, domid, &sdom) != 0 )
   44.48          return PyErr_SetFromErrno(xc_error);
   44.49  
   44.50      return Py_BuildValue("{s:H,s:H}",
   44.51 @@ -1084,8 +1084,8 @@ static PyMethodDef pyxc_methods[] = {
   44.52        " latency   [long]: domain's wakeup latency hint\n"
   44.53        " extratime [int]:  domain aware of extratime?\n"},
   44.54      
   44.55 -    { "csched_domain_set",
   44.56 -      (PyCFunction)pyxc_csched_domain_set,
   44.57 +    { "sched_credit_domain_set",
   44.58 +      (PyCFunction)pyxc_sched_credit_domain_set,
   44.59        METH_KEYWORDS, "\n"
   44.60        "Set the scheduling parameters for a domain when running with the\n"
   44.61        "SMP credit scheduler.\n"
   44.62 @@ -1093,8 +1093,8 @@ static PyMethodDef pyxc_methods[] = {
   44.63        " weight    [short]: domain's scheduling weight\n"
   44.64        "Returns: [int] 0 on success; -1 on error.\n" },
   44.65  
   44.66 -    { "csched_domain_get",
   44.67 -      (PyCFunction)pyxc_csched_domain_get,
   44.68 +    { "sched_credit_domain_get",
   44.69 +      (PyCFunction)pyxc_sched_credit_domain_get,
   44.70        METH_VARARGS, "\n"
   44.71        "Get the scheduling parameters for a domain when running with the\n"
   44.72        "SMP credit scheduler.\n"
    45.1 --- a/tools/python/xen/xend/XendDomain.py	Wed May 31 11:30:07 2006 -0600
    45.2 +++ b/tools/python/xen/xend/XendDomain.py	Wed May 31 13:05:21 2006 -0600
    45.3 @@ -522,25 +522,25 @@ class XendDomain:
    45.4          except Exception, ex:
    45.5              raise XendError(str(ex))
    45.6  
    45.7 -    def domain_csched_get(self, domid):
    45.8 +    def domain_sched_credit_get(self, domid):
    45.9          """Get credit scheduler parameters for a domain.
   45.10          """
   45.11          dominfo = self.domain_lookup_by_name_or_id_nr(domid)
   45.12          if not dominfo:
   45.13              raise XendInvalidDomain(str(domid))
   45.14          try:
   45.15 -            return xc.csched_domain_get(dominfo.getDomid())
   45.16 +            return xc.sched_credit_domain_get(dominfo.getDomid())
   45.17          except Exception, ex:
   45.18              raise XendError(str(ex))
   45.19      
   45.20 -    def domain_csched_set(self, domid, weight, cap):
   45.21 +    def domain_sched_credit_set(self, domid, weight, cap):
   45.22          """Set credit scheduler parameters for a domain.
   45.23          """
   45.24          dominfo = self.domain_lookup_by_name_or_id_nr(domid)
   45.25          if not dominfo:
   45.26              raise XendInvalidDomain(str(domid))
   45.27          try:
   45.28 -            return xc.csched_domain_set(dominfo.getDomid(), weight, cap)
   45.29 +            return xc.sched_credit_domain_set(dominfo.getDomid(), weight, cap)
   45.30          except Exception, ex:
   45.31              raise XendError(str(ex))
   45.32  
    46.1 --- a/tools/python/xen/xend/server/SrvDomain.py	Wed May 31 11:30:07 2006 -0600
    46.2 +++ b/tools/python/xen/xend/server/SrvDomain.py	Wed May 31 13:05:21 2006 -0600
    46.3 @@ -132,15 +132,15 @@ class SrvDomain(SrvDir):
    46.4          val = fn(req.args, {'dom': self.dom.domid})
    46.5          return val
    46.6      
    46.7 -    def op_domain_csched_get(self, _, req):
    46.8 -        fn = FormFn(self.xd.domain_csched_get,
    46.9 +    def op_domain_sched_credit_get(self, _, req):
   46.10 +        fn = FormFn(self.xd.domain_sched_credit_get,
   46.11                      [['dom', 'int']])
   46.12          val = fn(req.args, {'dom': self.dom.domid})
   46.13          return val
   46.14  
   46.15  
   46.16 -    def op_domain_csched_set(self, _, req):
   46.17 -        fn = FormFn(self.xd.domain_csched_set,
   46.18 +    def op_domain_sched_credit_set(self, _, req):
   46.19 +        fn = FormFn(self.xd.domain_sched_credit_set,
   46.20                      [['dom', 'int'],
   46.21                       ['weight', 'int']])
   46.22          val = fn(req.args, {'dom': self.dom.domid})
    47.1 --- a/tools/python/xen/xm/main.py	Wed May 31 11:30:07 2006 -0600
    47.2 +++ b/tools/python/xen/xm/main.py	Wed May 31 13:05:21 2006 -0600
    47.3 @@ -99,7 +99,7 @@ sched_sedf_help = "sched-sedf [DOM] [OPT
    47.4                                      specifies another way of setting a domain's\n\
    47.5                                      cpu period/slice."
    47.6  
    47.7 -csched_help = "csched                           Set or get credit scheduler parameters"
    47.8 +sched_credit_help = "sched-credit                           Set or get credit scheduler parameters"
    47.9  block_attach_help = """block-attach <DomId> <BackDev> <FrontDev> <Mode>
   47.10                  [BackDomId]         Create a new virtual block device"""
   47.11  block_detach_help = """block-detach  <DomId> <DevId>    Destroy a domain's virtual block device,
   47.12 @@ -175,7 +175,7 @@ host_commands = [
   47.13      ]
   47.14  
   47.15  scheduler_commands = [
   47.16 -    "csched",
   47.17 +    "sched-credit",
   47.18      "sched-bvt",
   47.19      "sched-bvt-ctxallow",
   47.20      "sched-sedf",
   47.21 @@ -737,11 +737,11 @@ def xm_sched_sedf(args):
   47.22          else:
   47.23              print_sedf(sedf_info)
   47.24  
   47.25 -def xm_csched(args):
   47.26 -    usage_msg = """Csched:     Set or get credit scheduler parameters
   47.27 +def xm_sched_credit(args):
   47.28 +    usage_msg = """sched-credit:     Set or get credit scheduler parameters
   47.29   Usage:
   47.30  
   47.31 -        csched -d domain [-w weight] [-c cap]
   47.32 +        sched-credit -d domain [-w weight] [-c cap]
   47.33      """
   47.34      try:
   47.35          opts, args = getopt.getopt(args[0:], "d:w:c:",
   47.36 @@ -769,14 +769,14 @@ def xm_csched(args):
   47.37          sys.exit(1)
   47.38  
   47.39      if weight is None and cap is None:
   47.40 -        print server.xend.domain.csched_get(domain)
   47.41 +        print server.xend.domain.sched_credit_get(domain)
   47.42      else:
   47.43          if weight is None:
   47.44              weight = int(0)
   47.45          if cap is None:
   47.46              cap = int(~0)
   47.47  
   47.48 -        err = server.xend.domain.csched_set(domain, weight, cap)
   47.49 +        err = server.xend.domain.sched_credit_set(domain, weight, cap)
   47.50          if err != 0:
   47.51              print err
   47.52  
   47.53 @@ -806,7 +806,7 @@ def xm_top(args):
   47.54      os.execvp('xentop', ['xentop'])
   47.55  
   47.56  def xm_dmesg(args):
   47.57 -    arg_check(args, "dmesg", 0)
   47.58 +    arg_check(args, "dmesg", 0, 1)
   47.59      
   47.60      gopts = Opts(use="""[-c|--clear]
   47.61  
   47.62 @@ -1076,7 +1076,7 @@ commands = {
   47.63      "sched-bvt": xm_sched_bvt,
   47.64      "sched-bvt-ctxallow": xm_sched_bvt_ctxallow,
   47.65      "sched-sedf": xm_sched_sedf,
   47.66 -    "csched": xm_csched,
   47.67 +    "sched-credit": xm_sched_credit,
   47.68      # block
   47.69      "block-attach": xm_block_attach,
   47.70      "block-detach": xm_block_detach,
    48.1 --- a/tools/vtpm/Makefile	Wed May 31 11:30:07 2006 -0600
    48.2 +++ b/tools/vtpm/Makefile	Wed May 31 13:05:21 2006 -0600
    48.3 @@ -9,7 +9,7 @@ TPM_EMULATOR_DIR = tpm_emulator
    48.4  VTPM_DIR = vtpm
    48.5  
    48.6  # Emulator tarball name
    48.7 -TPM_EMULATOR_TARFILE = tpm_emulator-0.2b.tar.gz
    48.8 +TPM_EMULATOR_TARFILE = tpm_emulator-0.3.tar.gz
    48.9  
   48.10  GMP_HEADER = /usr/include/gmp.h
   48.11  
   48.12 @@ -47,23 +47,23 @@ mrproper:
   48.13  
   48.14  # Create vtpm and TPM emulator dirs
   48.15  # apply patches for 1) used as dom0 tpm driver 2) used as vtpm device instance
   48.16 -$(TPM_EMULATOR_DIR): $(TPM_EMULATOR_TARFILE) tpm_emulator.patch tpm_emulator-0.2b-x86_64.patch
   48.17 +$(TPM_EMULATOR_DIR): $(TPM_EMULATOR_TARFILE) tpm_emulator.patch tpm_emulator-0.3-x86_64.patch
   48.18  	if [ "$(BUILD_EMULATOR)" = "y" ]; then \
   48.19  		tar -xzf $(TPM_EMULATOR_TARFILE); \
   48.20  		rm -rf $(TPM_EMULATOR_DIR); \
   48.21 -		mv tpm_emulator-0.2 $(TPM_EMULATOR_DIR); \
   48.22 +		mv tpm_emulator-0.3 $(TPM_EMULATOR_DIR); \
   48.23  		cd $(TPM_EMULATOR_DIR); \
   48.24 -		patch -p1 < ../tpm_emulator-0.2b-x86_64.patch; \
   48.25 +		patch -p1 < ../tpm_emulator-0.3-x86_64.patch; \
   48.26  		patch -p1 <../tpm_emulator.patch; \
   48.27  	fi
   48.28  
   48.29 -$(VTPM_DIR): $(TPM_EMULATOR_TARFILE) tpm_emulator-0.2b-x86_64.patch vtpm.patch
   48.30 +$(VTPM_DIR): $(TPM_EMULATOR_TARFILE) tpm_emulator-0.3-x86_64.patch vtpm.patch
   48.31  	tar -xzf $(TPM_EMULATOR_TARFILE);  
   48.32  	rm -rf $(VTPM_DIR)
   48.33 -	mv tpm_emulator-0.2 $(VTPM_DIR); 
   48.34 +	mv tpm_emulator-0.3 $(VTPM_DIR); 
   48.35  
   48.36  	cd $(VTPM_DIR); \
   48.37 -	patch -p1 < ../tpm_emulator-0.2b-x86_64.patch; \
   48.38 +	patch -p1 < ../tpm_emulator-0.3-x86_64.patch; \
   48.39  	patch -p1 <../vtpm.patch
   48.40  
   48.41  .PHONY: build_sub
    49.1 --- a/tools/vtpm/Rules.mk	Wed May 31 11:30:07 2006 -0600
    49.2 +++ b/tools/vtpm/Rules.mk	Wed May 31 13:05:21 2006 -0600
    49.3 @@ -33,6 +33,7 @@ OBJS	= $(patsubst %.c,%.o,$(SRCS))
    49.4  
    49.5  -include $(DEP_FILES)
    49.6  
    49.7 +# Emulator does not work on 64-bit systems, and may be broken on 32 right now
    49.8  BUILD_EMULATOR = n
    49.9  
   49.10  # Make sure these are just rules
    50.1 --- a/tools/vtpm/tpm_emulator-0.2b-x86_64.patch	Wed May 31 11:30:07 2006 -0600
    50.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    50.3 @@ -1,499 +0,0 @@
    50.4 -diff -uprN tpm_emulator-0.2/crypto/gmp_kernel_wrapper.c tpm_emulator-0.2-x86_64/crypto/gmp_kernel_wrapper.c
    50.5 ---- tpm_emulator-0.2/crypto/gmp_kernel_wrapper.c	2005-08-15 00:58:57.000000000 -0700
    50.6 -+++ tpm_emulator-0.2-x86_64/crypto/gmp_kernel_wrapper.c	2005-09-19 14:10:29.000000000 -0700
    50.7 -@@ -79,7 +79,7 @@ void __attribute__ ((regparm(0))) *kerne
    50.8 - {
    50.9 -   void *ret  = (void*)kmalloc(size, GFP_KERNEL);
   50.10 -   if (!ret) panic(KERN_CRIT TPM_MODULE_NAME 
   50.11 --    "GMP: cannot allocate memory (size=%u)\n", size);
   50.12 -+    "GMP: cannot allocate memory (size=%Zu)\n", size);
   50.13 -   return ret;
   50.14 - }
   50.15 - 
   50.16 -@@ -88,7 +88,7 @@ void __attribute__ ((regparm(0))) *kerne
   50.17 - {
   50.18 -   void *ret = (void*)kmalloc(new_size, GFP_KERNEL);
   50.19 -   if (!ret) panic(KERN_CRIT TPM_MODULE_NAME "GMP: Cannot reallocate memory "
   50.20 --    "(old_size=%u new_size=%u)\n", old_size, new_size);
   50.21 -+    "(old_size=%Zu new_size=%Zu)\n", old_size, new_size);
   50.22 -   memcpy(ret, oldptr, old_size);
   50.23 -   kfree(oldptr);
   50.24 -   return ret;
   50.25 -diff -uprN tpm_emulator-0.2/linux_module.c tpm_emulator-0.2-x86_64/linux_module.c
   50.26 ---- tpm_emulator-0.2/linux_module.c	2005-08-15 00:58:57.000000000 -0700
   50.27 -+++ tpm_emulator-0.2-x86_64/linux_module.c	2005-09-19 14:10:29.000000000 -0700
   50.28 -@@ -66,7 +66,7 @@ static int tpm_release(struct inode *ino
   50.29 - 
   50.30 - static ssize_t tpm_read(struct file *file, char *buf, size_t count, loff_t *ppos)
   50.31 - {
   50.32 --  debug("%s(%d)", __FUNCTION__, count);
   50.33 -+  debug("%s(%Zu)", __FUNCTION__, count);
   50.34 -   down(&tpm_mutex);
   50.35 -   if (tpm_response.data != NULL) {
   50.36 -     count = min(count, (size_t)tpm_response.size - (size_t)*ppos);
   50.37 -@@ -81,7 +81,7 @@ static ssize_t tpm_read(struct file *fil
   50.38 - 
   50.39 - static ssize_t tpm_write(struct file *file, const char *buf, size_t count, loff_t *ppos)
   50.40 - {
   50.41 --  debug("%s(%d)", __FUNCTION__, count);
   50.42 -+  debug("%s(%Zu)", __FUNCTION__, count);
   50.43 -   down(&tpm_mutex);
   50.44 -   *ppos = 0;
   50.45 -   if (tpm_response.data != NULL) kfree(tpm_response.data);
   50.46 -diff -uprN tpm_emulator-0.2/linux_module.h tpm_emulator-0.2-x86_64/linux_module.h
   50.47 ---- tpm_emulator-0.2/linux_module.h	2005-08-15 00:58:57.000000000 -0700
   50.48 -+++ tpm_emulator-0.2-x86_64/linux_module.h	2005-09-19 14:10:29.000000000 -0700
   50.49 -@@ -28,8 +28,10 @@
   50.50 - 
   50.51 - /* module settings */
   50.52 - 
   50.53 -+#ifndef STR
   50.54 - #define STR(s) __STR__(s)
   50.55 - #define __STR__(s) #s
   50.56 -+#endif
   50.57 - #include "tpm_version.h"
   50.58 - 
   50.59 - #define TPM_DEVICE_MINOR	224
   50.60 -diff -uprN tpm_emulator-0.2/Makefile tpm_emulator-0.2-x86_64/Makefile
   50.61 ---- tpm_emulator-0.2/Makefile	2005-08-15 00:58:57.000000000 -0700
   50.62 -+++ tpm_emulator-0.2-x86_64/Makefile	2005-09-19 14:10:29.000000000 -0700
   50.63 -@@ -7,6 +7,7 @@
   50.64 - KERNEL_RELEASE := $(shell uname -r)
   50.65 - KERNEL_BUILD   := /lib/modules/$(KERNEL_RELEASE)/build
   50.66 - MOD_SUBDIR     := misc
   50.67 -+COMPILE_ARCH    ?= $(shell uname -m | sed -e s/i.86/x86_32/)
   50.68 - 
   50.69 - # module settings
   50.70 - MODULE_NAME    := tpm_emulator
   50.71 -@@ -17,8 +18,14 @@ VERSION_BUILD  := $(shell date +"%s")
   50.72 - # enable/disable DEBUG messages
   50.73 - EXTRA_CFLAGS   += -DDEBUG -g  
   50.74 - 
   50.75 -+ifeq ($(COMPILE_ARCH),x86_64)
   50.76 -+LIBDIR = lib64
   50.77 -+else
   50.78 -+LIBDIR = lib
   50.79 -+endif
   50.80 -+
   50.81 - # GNU MP configuration
   50.82 --GMP_LIB        := /usr/lib/libgmp.a
   50.83 -+GMP_LIB        := /usr/$(LIBDIR)/libgmp.a
   50.84 - GMP_HEADER     := /usr/include/gmp.h
   50.85 - 
   50.86 - # sources and objects
   50.87 -diff -uprN tpm_emulator-0.2/README tpm_emulator-0.2-x86_64/README
   50.88 ---- tpm_emulator-0.2/README	2005-08-15 00:58:57.000000000 -0700
   50.89 -+++ tpm_emulator-0.2-x86_64/README	2005-09-19 14:21:43.000000000 -0700
   50.90 -@@ -45,6 +45,12 @@ Example:
   50.91 - GMP_LIB        := /usr/lib/libgmp.a
   50.92 - GMP_HEADER     := /usr/include/gmp.h
   50.93 - 
   50.94 -+GNU MP Library on 64 bit Systems
   50.95 -+--------------------------------------------------------------------------
   50.96 -+Some 64-bit kernels have problems with importing the user-space gmp 
   50.97 -+library (/usr/lib*/libgmp.a) into kernel space.  These kernels will require
   50.98 -+that the gmp library be recompiled for kernel space with -mcmodel=kernel.
   50.99 -+
  50.100 - Installation
  50.101 - --------------------------------------------------------------------------
  50.102 - The compilation and installation process uses the build environment for 
  50.103 -diff -uprN tpm_emulator-0.2/tpm/tpm_credentials.c tpm_emulator-0.2-x86_64/tpm/tpm_credentials.c
  50.104 ---- tpm_emulator-0.2/tpm/tpm_credentials.c	2005-08-15 00:58:57.000000000 -0700
  50.105 -+++ tpm_emulator-0.2-x86_64/tpm/tpm_credentials.c	2005-09-19 14:10:29.000000000 -0700
  50.106 -@@ -47,16 +47,16 @@ int tpm_compute_pubkey_checksum(TPM_NONC
  50.107 - 
  50.108 - TPM_RESULT tpm_get_pubek(TPM_PUBKEY *pubEndorsementKey)
  50.109 - {
  50.110 --  UINT32 key_length;
  50.111 -+  size_t key_length;
  50.112 -   if (!tpmData.permanent.data.endorsementKey.size) return TPM_NO_ENDORSEMENT;
  50.113 -   /* setup TPM_PUBKEY structure */
  50.114 --  key_length = tpmData.permanent.data.endorsementKey.size;
  50.115 --  pubEndorsementKey->pubKey.keyLength = key_length >> 3;
  50.116 -+  pubEndorsementKey->pubKey.keyLength = tpmData.permanent.data.endorsementKey.size >> 3;
  50.117 -   pubEndorsementKey->pubKey.key = tpm_malloc(pubEndorsementKey->pubKey.keyLength);
  50.118 -   if (pubEndorsementKey->pubKey.key == NULL) return TPM_FAIL;
  50.119 -   rsa_export_modulus(&tpmData.permanent.data.endorsementKey,
  50.120 --    pubEndorsementKey->pubKey.key,
  50.121 --    &pubEndorsementKey->pubKey.keyLength);
  50.122 -+		     pubEndorsementKey->pubKey.key,
  50.123 -+		     &key_length);
  50.124 -+  pubEndorsementKey->pubKey.keyLength = key_length;
  50.125 -   pubEndorsementKey->algorithmParms.algorithmID = TPM_ALG_RSA;
  50.126 -   pubEndorsementKey->algorithmParms.encScheme = TPM_ES_RSAESOAEP_SHA1_MGF1;
  50.127 -   pubEndorsementKey->algorithmParms.sigScheme = TPM_SS_NONE;
  50.128 -@@ -169,6 +169,7 @@ TPM_RESULT TPM_OwnerReadInternalPub(TPM_
  50.129 - {
  50.130 -   TPM_RESULT res;
  50.131 -   TPM_KEY_DATA *srk = &tpmData.permanent.data.srk;
  50.132 -+  size_t key_length;
  50.133 -   info("TPM_OwnerReadInternalPub()");
  50.134 -   /* verify authorization */
  50.135 -   res = tpm_verify_auth(auth1, tpmData.permanent.data.ownerAuth, TPM_KH_OWNER);
  50.136 -@@ -180,7 +181,8 @@ TPM_RESULT TPM_OwnerReadInternalPub(TPM_
  50.137 -     publicPortion->pubKey.key = tpm_malloc(publicPortion->pubKey.keyLength);
  50.138 -     if (publicPortion->pubKey.key == NULL) return TPM_FAIL;
  50.139 -     rsa_export_modulus(&srk->key, publicPortion->pubKey.key, 
  50.140 --      &publicPortion->pubKey.keyLength);
  50.141 -+      &key_length);
  50.142 -+    publicPortion->pubKey.keyLength = key_length;
  50.143 -     publicPortion->algorithmParms.algorithmID = TPM_ALG_RSA;
  50.144 -     publicPortion->algorithmParms.encScheme = srk->encScheme;
  50.145 -     publicPortion->algorithmParms.sigScheme = srk->sigScheme;
  50.146 -diff -uprN tpm_emulator-0.2/tpm/tpm_crypto.c tpm_emulator-0.2-x86_64/tpm/tpm_crypto.c
  50.147 ---- tpm_emulator-0.2/tpm/tpm_crypto.c	2005-08-15 00:58:57.000000000 -0700
  50.148 -+++ tpm_emulator-0.2-x86_64/tpm/tpm_crypto.c	2005-09-19 14:10:29.000000000 -0700
  50.149 -@@ -182,7 +182,8 @@ TPM_RESULT TPM_CertifyKey(TPM_KEY_HANDLE
  50.150 -   TPM_KEY_DATA *cert, *key;
  50.151 -   sha1_ctx_t sha1_ctx;
  50.152 -   BYTE *buf, *p;
  50.153 --  UINT32 length;
  50.154 -+  UINT32 length32;
  50.155 -+  size_t length;
  50.156 -   info("TPM_CertifyKey()");
  50.157 -   /* get keys */
  50.158 -   cert = tpm_get_key(certHandle);
  50.159 -@@ -264,14 +265,15 @@ TPM_RESULT TPM_CertifyKey(TPM_KEY_HANDLE
  50.160 -   /* compute the digest of the CERTIFY_INFO[2] structure and sign it */
  50.161 -   length = sizeof_TPM_CERTIFY_INFO((*certifyInfo));
  50.162 -   p = buf = tpm_malloc(length);
  50.163 -+  length32=(UINT32) length;
  50.164 -   if (buf == NULL
  50.165 --      || tpm_marshal_TPM_CERTIFY_INFO(&p, &length, certifyInfo)) {
  50.166 -+      || tpm_marshal_TPM_CERTIFY_INFO(&p, &length32, certifyInfo)) {
  50.167 -     free_TPM_KEY_PARMS(certifyInfo->algorithmParms);
  50.168 -     return TPM_FAIL;
  50.169 -   }
  50.170 -   length = sizeof_TPM_CERTIFY_INFO((*certifyInfo));
  50.171 -   sha1_init(&sha1_ctx);
  50.172 --  sha1_update(&sha1_ctx, buf, length);
  50.173 -+  sha1_update(&sha1_ctx, buf, (size_t) length);
  50.174 -   sha1_final(&sha1_ctx, buf);
  50.175 -   res = tpm_sign(cert, auth1, FALSE, buf, SHA1_DIGEST_LENGTH, outData, outDataSize);
  50.176 -   tpm_free(buf);
  50.177 -@@ -292,7 +294,8 @@ TPM_RESULT TPM_CertifyKey2(TPM_KEY_HANDL
  50.178 -   TPM_KEY_DATA *cert, *key;
  50.179 -   sha1_ctx_t sha1_ctx;
  50.180 -   BYTE *buf, *p;
  50.181 --  UINT32 length;
  50.182 -+  size_t length;
  50.183 -+  UINT32 length32;
  50.184 -   info("TPM_CertifyKey2()");
  50.185 -   /* get keys */
  50.186 -   cert = tpm_get_key(certHandle);
  50.187 -@@ -362,8 +365,9 @@ TPM_RESULT TPM_CertifyKey2(TPM_KEY_HANDL
  50.188 -   /* compute the digest of the CERTIFY_INFO[2] structure and sign it */
  50.189 -   length = sizeof_TPM_CERTIFY_INFO((*certifyInfo));
  50.190 -   p = buf = tpm_malloc(length);
  50.191 -+  length32 = (UINT32) length;
  50.192 -   if (buf == NULL
  50.193 --      || tpm_marshal_TPM_CERTIFY_INFO(&p, &length, certifyInfo)) {
  50.194 -+      || tpm_marshal_TPM_CERTIFY_INFO(&p, &length32, certifyInfo)) {
  50.195 -     free_TPM_KEY_PARMS(certifyInfo->algorithmParms);
  50.196 -     return TPM_FAIL;
  50.197 -   }
  50.198 -diff -uprN tpm_emulator-0.2/tpm/tpm_data.c tpm_emulator-0.2-x86_64/tpm/tpm_data.c
  50.199 ---- tpm_emulator-0.2/tpm/tpm_data.c	2005-08-15 00:58:57.000000000 -0700
  50.200 -+++ tpm_emulator-0.2-x86_64/tpm/tpm_data.c	2005-09-19 14:10:29.000000000 -0700
  50.201 -@@ -179,7 +179,7 @@ static int read_from_file(uint8_t **data
  50.202 - int tpm_store_permanent_data(void)
  50.203 - {
  50.204 -   uint8_t *buf, *ptr;
  50.205 --  size_t buf_length, len;
  50.206 -+  UINT32 buf_length, len;
  50.207 - 
  50.208 -   /* marshal data */
  50.209 -   buf_length = len = sizeof_TPM_STCLEAR_FLAGS(tpmData.stclear.flags)
  50.210 -@@ -207,13 +207,14 @@ int tpm_store_permanent_data(void)
  50.211 - int tpm_restore_permanent_data(void)
  50.212 - {
  50.213 -   uint8_t *buf, *ptr;
  50.214 --  size_t buf_length, len;
  50.215 -+  size_t buf_length;
  50.216 -+  UINT32 len;
  50.217 -   TPM_VERSION ver;
  50.218 - 
  50.219 -   /* read data */
  50.220 -   if (read_from_file(&buf, &buf_length)) return -1;
  50.221 -   ptr = buf;
  50.222 --  len = buf_length;
  50.223 -+  len = (uint32_t) buf_length;
  50.224 -   /* unmarshal data */
  50.225 -   if (tpm_unmarshal_TPM_VERSION(&ptr, &len, &ver)
  50.226 -       || memcmp(&ver, &tpmData.permanent.data.version, sizeof(TPM_VERSION))
  50.227 -diff -uprN tpm_emulator-0.2/tpm/tpm_marshalling.c tpm_emulator-0.2-x86_64/tpm/tpm_marshalling.c
  50.228 ---- tpm_emulator-0.2/tpm/tpm_marshalling.c	2005-08-15 00:58:57.000000000 -0700
  50.229 -+++ tpm_emulator-0.2-x86_64/tpm/tpm_marshalling.c	2005-09-19 14:10:29.000000000 -0700
  50.230 -@@ -981,7 +981,7 @@ int tpm_unmarshal_TPM_STANY_FLAGS(BYTE *
  50.231 - 
  50.232 - int tpm_marshal_RSA(BYTE **ptr, UINT32 *length, rsa_private_key_t *v)
  50.233 - {
  50.234 --  UINT32 m_len, e_len, q_len;
  50.235 -+  size_t m_len, e_len, q_len;
  50.236 -   if (*length < sizeof_RSA((*v))) return -1;
  50.237 -   if (v->size > 0) {
  50.238 -     rsa_export_modulus(v, &(*ptr)[6], &m_len);
  50.239 -diff -uprN tpm_emulator-0.2/tpm/tpm_owner.c tpm_emulator-0.2-x86_64/tpm/tpm_owner.c
  50.240 ---- tpm_emulator-0.2/tpm/tpm_owner.c	2005-08-15 00:58:57.000000000 -0700
  50.241 -+++ tpm_emulator-0.2-x86_64/tpm/tpm_owner.c	2005-09-19 14:10:29.000000000 -0700
  50.242 -@@ -108,7 +108,7 @@ TPM_RESULT TPM_TakeOwnership(TPM_PROTOCO
  50.243 -   TPM_RESULT res;
  50.244 -   rsa_private_key_t *ek = &tpmData.permanent.data.endorsementKey;
  50.245 -   TPM_KEY_DATA *srk = &tpmData.permanent.data.srk;
  50.246 --  UINT32 buf_size = ek->size >> 3;
  50.247 -+  size_t buf_size = ek->size >> 3, key_length; 
  50.248 -   BYTE buf[buf_size];
  50.249 - 
  50.250 -   info("TPM_TakeOwnership()");
  50.251 -@@ -172,7 +172,8 @@ TPM_RESULT TPM_TakeOwnership(TPM_PROTOCO
  50.252 -     return TPM_FAIL;
  50.253 -   }
  50.254 -   rsa_export_modulus(&srk->key, srkPub->pubKey.key,
  50.255 --    &srkPub->pubKey.keyLength);
  50.256 -+		     &key_length);
  50.257 -+  srkPub->pubKey.keyLength = (UINT32) key_length;
  50.258 -   /* setup tpmProof and set state to owned */
  50.259 -   tpm_get_random_bytes(tpmData.permanent.data.tpmProof.nonce, 
  50.260 -     sizeof(tpmData.permanent.data.tpmProof.nonce));
  50.261 -diff -uprN tpm_emulator-0.2/tpm/tpm_storage.c tpm_emulator-0.2-x86_64/tpm/tpm_storage.c
  50.262 ---- tpm_emulator-0.2/tpm/tpm_storage.c	2005-08-15 00:58:57.000000000 -0700
  50.263 -+++ tpm_emulator-0.2-x86_64/tpm/tpm_storage.c	2005-09-19 14:10:29.000000000 -0700
  50.264 -@@ -58,6 +58,7 @@ int encrypt_sealed_data(TPM_KEY_DATA *ke
  50.265 -                         BYTE *enc, UINT32 *enc_size)
  50.266 - {
  50.267 -   UINT32 len;
  50.268 -+  size_t enc_size32 = *enc_size;
  50.269 -   BYTE *buf, *ptr;
  50.270 -   rsa_public_key_t pub_key;
  50.271 -   int scheme;
  50.272 -@@ -72,7 +73,7 @@ int encrypt_sealed_data(TPM_KEY_DATA *ke
  50.273 -   if (buf == NULL
  50.274 -       || tpm_marshal_TPM_SEALED_DATA(&ptr, &len, seal)
  50.275 -       || rsa_encrypt(&pub_key, scheme, buf, sizeof_TPM_SEALED_DATA((*seal)),
  50.276 --                     enc, enc_size)) {
  50.277 -+                     enc, &enc_size32)) {
  50.278 -     tpm_free(buf);
  50.279 -     rsa_release_public_key(&pub_key);
  50.280 -     return -1;
  50.281 -@@ -85,7 +86,8 @@ int encrypt_sealed_data(TPM_KEY_DATA *ke
  50.282 - int decrypt_sealed_data(TPM_KEY_DATA *key, BYTE *enc, UINT32 enc_size,
  50.283 -                         TPM_SEALED_DATA *seal, BYTE **buf) 
  50.284 - {
  50.285 --  UINT32 len;
  50.286 -+  size_t len;
  50.287 -+  UINT32 len32;
  50.288 -   BYTE *ptr;
  50.289 -   int scheme;
  50.290 -   switch (key->encScheme) {
  50.291 -@@ -96,8 +98,12 @@ int decrypt_sealed_data(TPM_KEY_DATA *ke
  50.292 -   len = enc_size;
  50.293 -   *buf = ptr = tpm_malloc(len);
  50.294 -   if (*buf == NULL
  50.295 --      || rsa_decrypt(&key->key, scheme, enc, enc_size, *buf, &len)
  50.296 --      || tpm_unmarshal_TPM_SEALED_DATA(&ptr, &len, seal)) {
  50.297 -+      || rsa_decrypt(&key->key, scheme, enc, enc_size, *buf, &len) ){
  50.298 -+    tpm_free(*buf);
  50.299 -+    return -1;
  50.300 -+  }
  50.301 -+  len32 = len;
  50.302 -+  if (tpm_unmarshal_TPM_SEALED_DATA(&ptr, &len32, seal)) {
  50.303 -     tpm_free(*buf);
  50.304 -     return -1;
  50.305 -   }
  50.306 -@@ -237,11 +243,12 @@ TPM_RESULT TPM_Unseal(TPM_KEY_HANDLE par
  50.307 - 
  50.308 - TPM_RESULT TPM_UnBind(TPM_KEY_HANDLE keyHandle, UINT32 inDataSize,
  50.309 -                       BYTE *inData, TPM_AUTH *auth1, 
  50.310 --                      UINT32 *outDataSize, BYTE **outData)
  50.311 -+                      UINT32 *outDataSize32, BYTE **outData)
  50.312 - {
  50.313 -   TPM_RESULT res;
  50.314 -   TPM_KEY_DATA *key;
  50.315 -   int scheme;
  50.316 -+  size_t outDataSize;
  50.317 -   info("TPM_UnBind()");
  50.318 -   /* get key */
  50.319 -   key = tpm_get_key(keyHandle);
  50.320 -@@ -258,8 +265,8 @@ TPM_RESULT TPM_UnBind(TPM_KEY_HANDLE key
  50.321 -   /* the size of the input data muss be greater than zero */
  50.322 -   if (inDataSize == 0) return TPM_BAD_PARAMETER;
  50.323 -   /* decrypt data */
  50.324 --  *outDataSize = inDataSize;
  50.325 --  *outData = tpm_malloc(*outDataSize);
  50.326 -+  outDataSize = inDataSize;
  50.327 -+  *outData = tpm_malloc(outDataSize);
  50.328 -   if (*outData == NULL) return TPM_FAIL;
  50.329 -   switch (key->encScheme) {
  50.330 -     case TPM_ES_RSAESOAEP_SHA1_MGF1: scheme = RSA_ES_OAEP_SHA1; break;
  50.331 -@@ -267,20 +274,21 @@ TPM_RESULT TPM_UnBind(TPM_KEY_HANDLE key
  50.332 -     default: tpm_free(*outData); return TPM_DECRYPT_ERROR;
  50.333 -   }
  50.334 -   if (rsa_decrypt(&key->key, scheme, inData, inDataSize, 
  50.335 --      *outData, outDataSize)) {
  50.336 -+		  *outData, &outDataSize) ) { 
  50.337 -     tpm_free(*outData);
  50.338 -     return TPM_DECRYPT_ERROR;
  50.339 -   }
  50.340 -   /* verify data if it is of type TPM_BOUND_DATA */
  50.341 -   if (key->encScheme == TPM_ES_RSAESOAEP_SHA1_MGF1 
  50.342 -       || key->keyUsage != TPM_KEY_LEGACY) {
  50.343 --    if (*outDataSize < 5 || memcmp(*outData, "\x01\x01\00\x00\x02", 5) != 0) {
  50.344 -+    if (outDataSize < 5 || memcmp(*outData, "\x01\x01\00\x00\x02", 5) != 0) {
  50.345 -       tpm_free(*outData);
  50.346 -       return TPM_DECRYPT_ERROR;
  50.347 -     }
  50.348 --    *outDataSize -= 5;
  50.349 --    memmove(*outData, &(*outData)[5], *outDataSize);   
  50.350 --  } 
  50.351 -+    outDataSize -= 5;
  50.352 -+    memmove(*outData, &(*outData)[5], outDataSize);   
  50.353 -+  }
  50.354 -+  *outDataSize32 = (UINT32) outDataSize; 
  50.355 -   return TPM_SUCCESS;
  50.356 - }
  50.357 - 
  50.358 -@@ -311,12 +319,13 @@ static int verify_key_digest(TPM_KEY *ke
  50.359 - }
  50.360 - 
  50.361 - int encrypt_private_key(TPM_KEY_DATA *key, TPM_STORE_ASYMKEY *store,
  50.362 --                        BYTE *enc, UINT32 *enc_size)
  50.363 -+                        BYTE *enc, UINT32 *enc_size32)
  50.364 - {
  50.365 -   UINT32 len;
  50.366 -   BYTE *buf, *ptr;
  50.367 -   rsa_public_key_t pub_key;
  50.368 -   int scheme;
  50.369 -+  size_t enc_size;
  50.370 -   switch (key->encScheme) {
  50.371 -     case TPM_ES_RSAESOAEP_SHA1_MGF1: scheme = RSA_ES_OAEP_SHA1; break;
  50.372 -     case TPM_ES_RSAESPKCSv15: scheme = RSA_ES_PKCSV15; break;
  50.373 -@@ -328,11 +337,12 @@ int encrypt_private_key(TPM_KEY_DATA *ke
  50.374 -   if (buf == NULL
  50.375 -       || tpm_marshal_TPM_STORE_ASYMKEY(&ptr, &len, store)
  50.376 -       || rsa_encrypt(&pub_key, scheme, buf, sizeof_TPM_STORE_ASYMKEY((*store)),
  50.377 --                     enc, enc_size)) {
  50.378 -+                     enc, &enc_size)) {
  50.379 -     tpm_free(buf);
  50.380 -     rsa_release_public_key(&pub_key);
  50.381 -     return -1;
  50.382 -   }
  50.383 -+  *enc_size32 = (UINT32) enc_size;
  50.384 -   tpm_free(buf);
  50.385 -   rsa_release_public_key(&pub_key);
  50.386 -   return 0;
  50.387 -@@ -341,7 +351,8 @@ int encrypt_private_key(TPM_KEY_DATA *ke
  50.388 - int decrypt_private_key(TPM_KEY_DATA *key, BYTE *enc, UINT32 enc_size, 
  50.389 -                         TPM_STORE_ASYMKEY *store, BYTE **buf) 
  50.390 - {
  50.391 --  UINT32 len;
  50.392 -+  UINT32 len32;
  50.393 -+  size_t len;
  50.394 -   BYTE *ptr;
  50.395 -   int scheme;
  50.396 -   switch (key->encScheme) {
  50.397 -@@ -352,11 +363,16 @@ int decrypt_private_key(TPM_KEY_DATA *ke
  50.398 -   len = enc_size;
  50.399 -   *buf = ptr = tpm_malloc(len);
  50.400 -   if (*buf == NULL
  50.401 --      || rsa_decrypt(&key->key, scheme, enc, enc_size, *buf, &len)
  50.402 --      || tpm_unmarshal_TPM_STORE_ASYMKEY(&ptr, &len, store)) {
  50.403 -+      || rsa_decrypt(&key->key, scheme, enc, enc_size, *buf, &len) ) {
  50.404 -+    tpm_free(*buf);
  50.405 -+    return -1;
  50.406 -+  }
  50.407 -+  len32 = (UINT32) len;
  50.408 -+  if (tpm_unmarshal_TPM_STORE_ASYMKEY(&ptr, &len32, store)) {  
  50.409 -     tpm_free(*buf);
  50.410 -     return -1;
  50.411 -   }
  50.412 -+
  50.413 -   return 0;
  50.414 - }
  50.415 - 
  50.416 -@@ -371,7 +387,7 @@ TPM_RESULT TPM_CreateWrapKey(TPM_KEY_HAN
  50.417 -   TPM_SESSION_DATA *session;
  50.418 -   TPM_STORE_ASYMKEY store;
  50.419 -   rsa_private_key_t rsa;
  50.420 --  UINT32 key_length;
  50.421 -+  size_t key_length;
  50.422 - 
  50.423 -   info("TPM_CreateWrapKey()");
  50.424 -   /* get parent key */
  50.425 -@@ -428,11 +444,11 @@ TPM_RESULT TPM_CreateWrapKey(TPM_KEY_HAN
  50.426 -   }
  50.427 -   if (compute_key_digest(wrappedKey, &store.pubDataDigest)) return TPM_FAIL;
  50.428 -   /* generate key and store it */
  50.429 --  key_length = keyInfo->algorithmParms.parms.rsa.keyLength;
  50.430 --  if (rsa_generate_key(&rsa, key_length)) return TPM_FAIL;
  50.431 --  wrappedKey->pubKey.keyLength = key_length >> 3;
  50.432 -+  if (rsa_generate_key(&rsa, keyInfo->algorithmParms.parms.rsa.keyLength)) 
  50.433 -+    return TPM_FAIL;
  50.434 -+  wrappedKey->pubKey.keyLength = keyInfo->algorithmParms.parms.rsa.keyLength >> 3;
  50.435 -   wrappedKey->pubKey.key = tpm_malloc(wrappedKey->pubKey.keyLength);
  50.436 --  store.privKey.keyLength = key_length >> 4;
  50.437 -+  store.privKey.keyLength = keyInfo->algorithmParms.parms.rsa.keyLength >> 4;
  50.438 -   store.privKey.key = tpm_malloc(store.privKey.keyLength);
  50.439 -   wrappedKey->encDataSize = parent->key.size >> 3;
  50.440 -   wrappedKey->encData = tpm_malloc(wrappedKey->encDataSize);
  50.441 -@@ -444,9 +460,11 @@ TPM_RESULT TPM_CreateWrapKey(TPM_KEY_HAN
  50.442 -     tpm_free(wrappedKey->encData);
  50.443 -     return TPM_FAIL;
  50.444 -   }
  50.445 --  rsa_export_modulus(&rsa, wrappedKey->pubKey.key, 
  50.446 --    &wrappedKey->pubKey.keyLength);
  50.447 --  rsa_export_prime1(&rsa, store.privKey.key, &store.privKey.keyLength);
  50.448 -+  rsa_export_modulus(&rsa, wrappedKey->pubKey.key,
  50.449 -+		     &key_length);
  50.450 -+  wrappedKey->pubKey.keyLength = (UINT32) key_length;
  50.451 -+  rsa_export_prime1(&rsa, store.privKey.key, &key_length);
  50.452 -+  store.privKey.keyLength = (UINT32) key_length;
  50.453 -   rsa_release_private_key(&rsa);
  50.454 -   /* encrypt private key data */
  50.455 -   if (encrypt_private_key(parent, &store, wrappedKey->encData, 
  50.456 -@@ -560,6 +578,7 @@ TPM_RESULT TPM_LoadKey(TPM_KEY_HANDLE pa
  50.457 - 
  50.458 - int tpm_setup_key_parms(TPM_KEY_DATA *key, TPM_KEY_PARMS *parms)
  50.459 - {
  50.460 -+  size_t key_length;
  50.461 -   parms->algorithmID = TPM_ALG_RSA;
  50.462 -   parms->encScheme = key->encScheme;
  50.463 -   parms->sigScheme = key->sigScheme;
  50.464 -@@ -569,7 +588,8 @@ int tpm_setup_key_parms(TPM_KEY_DATA *ke
  50.465 -   parms->parms.rsa.exponent = tpm_malloc(parms->parms.rsa.exponentSize);
  50.466 -   if (parms->parms.rsa.exponent == NULL) return -1;
  50.467 -   rsa_export_exponent(&key->key, parms->parms.rsa.exponent,
  50.468 --    &parms->parms.rsa.exponentSize);
  50.469 -+                      &key_length);  
  50.470 -+  parms->parms.rsa.exponentSize = (UINT32) key_length;
  50.471 -   parms->parmSize = 12 + parms->parms.rsa.exponentSize;  
  50.472 -   return 0;
  50.473 - }
  50.474 -@@ -580,6 +600,7 @@ TPM_RESULT TPM_GetPubKey(TPM_KEY_HANDLE 
  50.475 -   TPM_RESULT res;
  50.476 -   TPM_KEY_DATA *key;
  50.477 -   TPM_DIGEST digest;
  50.478 -+  size_t key_length;
  50.479 -   info("TPM_GetPubKey()");
  50.480 -   /* get key */
  50.481 -   if (keyHandle == TPM_KH_SRK) return TPM_BAD_PARAMETER;
  50.482 -@@ -607,8 +628,8 @@ TPM_RESULT TPM_GetPubKey(TPM_KEY_HANDLE 
  50.483 -   pubKey->pubKey.keyLength = key->key.size >> 3;
  50.484 -   pubKey->pubKey.key = tpm_malloc(pubKey->pubKey.keyLength);
  50.485 -   if (pubKey->pubKey.key == NULL) return TPM_FAIL;
  50.486 --  rsa_export_modulus(&key->key, pubKey->pubKey.key, 
  50.487 --    &pubKey->pubKey.keyLength);
  50.488 -+  rsa_export_modulus(&key->key, pubKey->pubKey.key, &key_length); 
  50.489 -+  pubKey->pubKey.keyLength = (UINT32) key_length;
  50.490 -   if (tpm_setup_key_parms(key, &pubKey->algorithmParms) != 0) {
  50.491 -     tpm_free(pubKey->pubKey.key);
  50.492 -     return TPM_FAIL;  
  50.493 -diff -uprN tpm_emulator-0.2/tpm_version.h tpm_emulator-0.2-x86_64/tpm_version.h
  50.494 ---- tpm_emulator-0.2/tpm_version.h	2005-08-15 00:58:57.000000000 -0700
  50.495 -+++ tpm_emulator-0.2-x86_64/tpm_version.h	1969-12-31 16:00:00.000000000 -0800
  50.496 -@@ -1,6 +0,0 @@
  50.497 --#ifndef _TPM_VERSION_H_
  50.498 --#define _TPM_VERSION_H_
  50.499 --#define VERSION_MAJOR 0
  50.500 --#define VERSION_MINOR 2
  50.501 --#define VERSION_BUILD 1123950310
  50.502 --#endif /* _TPM_VERSION_H_ */
    51.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    51.2 +++ b/tools/vtpm/tpm_emulator-0.3-x86_64.patch	Wed May 31 13:05:21 2006 -0600
    51.3 @@ -0,0 +1,484 @@
    51.4 +diff -uprN tpm_emulator-0.3/crypto/gmp_kernel_wrapper.c tpm_emulator-0.3-x86_64/crypto/gmp_kernel_wrapper.c
    51.5 +--- tpm_emulator-0.3/crypto/gmp_kernel_wrapper.c	2006-01-10 04:21:45.000000000 -0800
    51.6 ++++ tpm_emulator-0.3-x86_64/crypto/gmp_kernel_wrapper.c	2006-05-26 11:26:02.000000000 -0700
    51.7 +@@ -79,7 +79,7 @@ void __attribute__ ((regparm(0))) *kerne
    51.8 + {
    51.9 +   void *ret  = (void*)kmalloc(size, GFP_KERNEL);
   51.10 +   if (!ret) panic(KERN_CRIT TPM_MODULE_NAME 
   51.11 +-    "GMP: cannot allocate memory (size=%u)\n", size);
   51.12 ++    "GMP: cannot allocate memory (size=%Zu)\n", size);
   51.13 +   return ret;
   51.14 + }
   51.15 + 
   51.16 +@@ -88,7 +88,7 @@ void __attribute__ ((regparm(0))) *kerne
   51.17 + {
   51.18 +   void *ret = (void*)kmalloc(new_size, GFP_KERNEL);
   51.19 +   if (!ret) panic(KERN_CRIT TPM_MODULE_NAME "GMP: Cannot reallocate memory "
   51.20 +-    "(old_size=%u new_size=%u)\n", old_size, new_size);
   51.21 ++    "(old_size=%Zu new_size=%Zu)\n", old_size, new_size);
   51.22 +   memcpy(ret, oldptr, old_size);
   51.23 +   kfree(oldptr);
   51.24 +   return ret;
   51.25 +diff -uprN tpm_emulator-0.3/linux_module.c tpm_emulator-0.3-x86_64/linux_module.c
   51.26 +--- tpm_emulator-0.3/linux_module.c	2006-01-10 04:21:45.000000000 -0800
   51.27 ++++ tpm_emulator-0.3-x86_64/linux_module.c	2006-05-26 11:26:02.000000000 -0700
   51.28 +@@ -72,7 +72,7 @@ static int tpm_release(struct inode *ino
   51.29 + 
   51.30 + static ssize_t tpm_read(struct file *file, char *buf, size_t count, loff_t *ppos)
   51.31 + {
   51.32 +-  debug("%s(%d)", __FUNCTION__, count);
   51.33 ++  debug("%s(%Zu)", __FUNCTION__, count);
   51.34 +   down(&tpm_mutex);
   51.35 +   if (tpm_response.data != NULL) {
   51.36 +     count = min(count, (size_t)tpm_response.size - (size_t)*ppos);
   51.37 +@@ -91,7 +91,7 @@ static ssize_t tpm_read(struct file *fil
   51.38 + 
   51.39 + static ssize_t tpm_write(struct file *file, const char *buf, size_t count, loff_t *ppos)
   51.40 + {
   51.41 +-  debug("%s(%d)", __FUNCTION__, count);
   51.42 ++  debug("%s(%Zu)", __FUNCTION__, count);
   51.43 +   down(&tpm_mutex);
   51.44 +   *ppos = 0;
   51.45 +   if (tpm_response.data != NULL) kfree(tpm_response.data);
   51.46 +diff -uprN tpm_emulator-0.3/linux_module.h tpm_emulator-0.3-x86_64/linux_module.h
   51.47 +--- tpm_emulator-0.3/linux_module.h	2006-01-10 04:21:45.000000000 -0800
   51.48 ++++ tpm_emulator-0.3-x86_64/linux_module.h	2006-05-26 11:26:02.000000000 -0700
   51.49 +@@ -28,8 +28,10 @@
   51.50 + 
   51.51 + /* module settings */
   51.52 + 
   51.53 ++#ifndef STR
   51.54 + #define STR(s) __STR__(s)
   51.55 + #define __STR__(s) #s
   51.56 ++#endif
   51.57 + #include "tpm_version.h"
   51.58 + 
   51.59 + #define TPM_DEVICE_MINOR	224
   51.60 +diff -uprN tpm_emulator-0.3/Makefile tpm_emulator-0.3-x86_64/Makefile
   51.61 +--- tpm_emulator-0.3/Makefile	2006-01-10 04:21:45.000000000 -0800
   51.62 ++++ tpm_emulator-0.3-x86_64/Makefile	2006-05-26 11:26:02.000000000 -0700
   51.63 +@@ -7,6 +7,7 @@
   51.64 + KERNEL_RELEASE := $(shell uname -r)
   51.65 + KERNEL_BUILD   := /lib/modules/$(KERNEL_RELEASE)/build
   51.66 + MOD_SUBDIR     := misc
   51.67 ++COMPILE_ARCH    ?= $(shell uname -m | sed -e s/i.86/x86_32/)
   51.68 + 
   51.69 + # module settings
   51.70 + MODULE_NAME    := tpm_emulator
   51.71 +@@ -17,8 +18,14 @@ VERSION_BUILD  := $(shell date +"%s")
   51.72 + # enable/disable DEBUG messages
   51.73 + EXTRA_CFLAGS   += -Wall -DDEBUG -g  
   51.74 + 
   51.75 ++ifeq ($(COMPILE_ARCH),x86_64)
   51.76 ++LIBDIR = lib64
   51.77 ++else
   51.78 ++LIBDIR = lib
   51.79 ++endif
   51.80 ++
   51.81 + # GNU MP configuration
   51.82 +-GMP_LIB        := /usr/lib/libgmp.a
   51.83 ++GMP_LIB        := /usr/$(LIBDIR)/libgmp.a
   51.84 + GMP_HEADER     := /usr/include/gmp.h
   51.85 + 
   51.86 + # sources and objects
   51.87 +diff -uprN tpm_emulator-0.3/README tpm_emulator-0.3-x86_64/README
   51.88 +--- tpm_emulator-0.3/README	2006-01-10 04:21:45.000000000 -0800
   51.89 ++++ tpm_emulator-0.3-x86_64/README	2006-05-26 11:26:02.000000000 -0700
   51.90 +@@ -43,6 +43,12 @@ Example:
   51.91 + GMP_LIB        := /usr/lib/libgmp.a
   51.92 + GMP_HEADER     := /usr/include/gmp.h
   51.93 + 
   51.94 ++GNU MP Library on 64 bit Systems
   51.95 ++--------------------------------------------------------------------------
   51.96 ++Some 64-bit kernels have problems with importing the user-space gmp 
   51.97 ++library (/usr/lib*/libgmp.a) into kernel space.  These kernels will require
   51.98 ++that the gmp library be recompiled for kernel space with -mcmodel=kernel.
   51.99 ++
  51.100 + Installation
  51.101 + --------------------------------------------------------------------------
  51.102 + The compilation and installation process uses the build environment for 
  51.103 +diff -uprN tpm_emulator-0.3/tpm/tpm_credentials.c tpm_emulator-0.3-x86_64/tpm/tpm_credentials.c
  51.104 +--- tpm_emulator-0.3/tpm/tpm_credentials.c	2006-01-10 04:21:45.000000000 -0800
  51.105 ++++ tpm_emulator-0.3-x86_64/tpm/tpm_credentials.c	2006-05-26 11:26:02.000000000 -0700
  51.106 +@@ -47,16 +47,16 @@ int tpm_compute_pubkey_checksum(TPM_NONC
  51.107 + 
  51.108 + TPM_RESULT tpm_get_pubek(TPM_PUBKEY *pubEndorsementKey)
  51.109 + {
  51.110 +-  UINT32 key_length;
  51.111 ++  size_t key_length;
  51.112 +   if (!tpmData.permanent.data.endorsementKey.size) return TPM_NO_ENDORSEMENT;
  51.113 +   /* setup TPM_PUBKEY structure */
  51.114 +-  key_length = tpmData.permanent.data.endorsementKey.size;
  51.115 +-  pubEndorsementKey->pubKey.keyLength = key_length >> 3;
  51.116 ++  pubEndorsementKey->pubKey.keyLength = tpmData.permanent.data.endorsementKey.size >> 3;
  51.117 +   pubEndorsementKey->pubKey.key = tpm_malloc(pubEndorsementKey->pubKey.keyLength);
  51.118 +   if (pubEndorsementKey->pubKey.key == NULL) return TPM_FAIL;
  51.119 +   rsa_export_modulus(&tpmData.permanent.data.endorsementKey,
  51.120 +-    pubEndorsementKey->pubKey.key,
  51.121 +-    &pubEndorsementKey->pubKey.keyLength);
  51.122 ++		     pubEndorsementKey->pubKey.key,
  51.123 ++		     &key_length);
  51.124 ++  pubEndorsementKey->pubKey.keyLength = key_length;
  51.125 +   pubEndorsementKey->algorithmParms.algorithmID = TPM_ALG_RSA;
  51.126 +   pubEndorsementKey->algorithmParms.encScheme = TPM_ES_RSAESOAEP_SHA1_MGF1;
  51.127 +   pubEndorsementKey->algorithmParms.sigScheme = TPM_SS_NONE;
  51.128 +@@ -175,6 +175,7 @@ TPM_RESULT TPM_OwnerReadInternalPub(TPM_
  51.129 + {
  51.130 +   TPM_RESULT res;
  51.131 +   TPM_KEY_DATA *srk = &tpmData.permanent.data.srk;
  51.132 ++  size_t key_length;
  51.133 +   info("TPM_OwnerReadInternalPub()");
  51.134 +   /* verify authorization */
  51.135 +   res = tpm_verify_auth(auth1, tpmData.permanent.data.ownerAuth, TPM_KH_OWNER);
  51.136 +@@ -186,7 +187,8 @@ TPM_RESULT TPM_OwnerReadInternalPub(TPM_
  51.137 +     publicPortion->pubKey.key = tpm_malloc(publicPortion->pubKey.keyLength);
  51.138 +     if (publicPortion->pubKey.key == NULL) return TPM_FAIL;
  51.139 +     rsa_export_modulus(&srk->key, publicPortion->pubKey.key, 
  51.140 +-      &publicPortion->pubKey.keyLength);
  51.141 ++      &key_length);
  51.142 ++    publicPortion->pubKey.keyLength = key_length;
  51.143 +     publicPortion->algorithmParms.algorithmID = TPM_ALG_RSA;
  51.144 +     publicPortion->algorithmParms.encScheme = srk->encScheme;
  51.145 +     publicPortion->algorithmParms.sigScheme = srk->sigScheme;
  51.146 +diff -uprN tpm_emulator-0.3/tpm/tpm_crypto.c tpm_emulator-0.3-x86_64/tpm/tpm_crypto.c
  51.147 +--- tpm_emulator-0.3/tpm/tpm_crypto.c	2006-01-10 04:21:45.000000000 -0800
  51.148 ++++ tpm_emulator-0.3-x86_64/tpm/tpm_crypto.c	2006-05-26 11:26:02.000000000 -0700
  51.149 +@@ -182,7 +182,8 @@ TPM_RESULT TPM_CertifyKey(TPM_KEY_HANDLE
  51.150 +   TPM_KEY_DATA *cert, *key;
  51.151 +   sha1_ctx_t sha1_ctx;
  51.152 +   BYTE *buf, *p;
  51.153 +-  UINT32 length;
  51.154 ++  UINT32 length32;
  51.155 ++  size_t length;
  51.156 +   info("TPM_CertifyKey()");
  51.157 +   /* get keys */
  51.158 +   cert = tpm_get_key(certHandle);
  51.159 +@@ -264,14 +265,15 @@ TPM_RESULT TPM_CertifyKey(TPM_KEY_HANDLE
  51.160 +   /* compute the digest of the CERTIFY_INFO[2] structure and sign it */
  51.161 +   length = sizeof_TPM_CERTIFY_INFO((*certifyInfo));
  51.162 +   p = buf = tpm_malloc(length);
  51.163 ++  length32=(UINT32) length;
  51.164 +   if (buf == NULL
  51.165 +-      || tpm_marshal_TPM_CERTIFY_INFO(&p, &length, certifyInfo)) {
  51.166 ++      || tpm_marshal_TPM_CERTIFY_INFO(&p, &length32, certifyInfo)) {
  51.167 +     free_TPM_KEY_PARMS(certifyInfo->algorithmParms);
  51.168 +     return TPM_FAIL;
  51.169 +   }
  51.170 +   length = sizeof_TPM_CERTIFY_INFO((*certifyInfo));
  51.171 +   sha1_init(&sha1_ctx);
  51.172 +-  sha1_update(&sha1_ctx, buf, length);
  51.173 ++  sha1_update(&sha1_ctx, buf, (size_t) length);
  51.174 +   sha1_final(&sha1_ctx, buf);
  51.175 +   res = tpm_sign(cert, auth1, FALSE, buf, SHA1_DIGEST_LENGTH, outData, outDataSize);
  51.176 +   tpm_free(buf);
  51.177 +@@ -292,7 +294,8 @@ TPM_RESULT TPM_CertifyKey2(TPM_KEY_HANDL
  51.178 +   TPM_KEY_DATA *cert, *key;
  51.179 +   sha1_ctx_t sha1_ctx;
  51.180 +   BYTE *buf, *p;
  51.181 +-  UINT32 length;
  51.182 ++  size_t length;
  51.183 ++  UINT32 length32;
  51.184 +   info("TPM_CertifyKey2()");
  51.185 +   /* get keys */
  51.186 +   cert = tpm_get_key(certHandle);
  51.187 +@@ -362,8 +365,9 @@ TPM_RESULT TPM_CertifyKey2(TPM_KEY_HANDL
  51.188 +   /* compute the digest of the CERTIFY_INFO[2] structure and sign it */
  51.189 +   length = sizeof_TPM_CERTIFY_INFO((*certifyInfo));
  51.190 +   p = buf = tpm_malloc(length);
  51.191 ++  length32 = (UINT32) length;
  51.192 +   if (buf == NULL
  51.193 +-      || tpm_marshal_TPM_CERTIFY_INFO(&p, &length, certifyInfo)) {
  51.194 ++      || tpm_marshal_TPM_CERTIFY_INFO(&p, &length32, certifyInfo)) {
  51.195 +     free_TPM_KEY_PARMS(certifyInfo->algorithmParms);
  51.196 +     return TPM_FAIL;
  51.197 +   }
  51.198 +diff -uprN tpm_emulator-0.3/tpm/tpm_data.c tpm_emulator-0.3-x86_64/tpm/tpm_data.c
  51.199 +--- tpm_emulator-0.3/tpm/tpm_data.c	2006-01-10 04:21:45.000000000 -0800
  51.200 ++++ tpm_emulator-0.3-x86_64/tpm/tpm_data.c	2006-05-26 11:26:02.000000000 -0700
  51.201 +@@ -214,7 +214,7 @@ static int read_from_file(uint8_t **data
  51.202 + int tpm_store_permanent_data(void)
  51.203 + {
  51.204 +   uint8_t *buf, *ptr;
  51.205 +-  size_t buf_length, len;
  51.206 ++  UINT32 buf_length, len;
  51.207 + 
  51.208 +   /* marshal data */
  51.209 +   buf_length = len = sizeof_TPM_STCLEAR_FLAGS(tpmData.stclear.flags)
  51.210 +@@ -242,13 +242,14 @@ int tpm_store_permanent_data(void)
  51.211 + int tpm_restore_permanent_data(void)
  51.212 + {
  51.213 +   uint8_t *buf, *ptr;
  51.214 +-  size_t buf_length, len;
  51.215 ++  size_t buf_length;
  51.216 ++  UINT32 len;
  51.217 +   TPM_VERSION ver;
  51.218 + 
  51.219 +   /* read data */
  51.220 +   if (read_from_file(&buf, &buf_length)) return -1;
  51.221 +   ptr = buf;
  51.222 +-  len = buf_length;
  51.223 ++  len = (uint32_t) buf_length;
  51.224 +   /* unmarshal data */
  51.225 +   if (tpm_unmarshal_TPM_VERSION(&ptr, &len, &ver)
  51.226 +       || memcmp(&ver, &tpmData.permanent.data.version, sizeof(TPM_VERSION))
  51.227 +diff -uprN tpm_emulator-0.3/tpm/tpm_marshalling.c tpm_emulator-0.3-x86_64/tpm/tpm_marshalling.c
  51.228 +--- tpm_emulator-0.3/tpm/tpm_marshalling.c	2006-01-10 04:21:45.000000000 -0800
  51.229 ++++ tpm_emulator-0.3-x86_64/tpm/tpm_marshalling.c	2006-05-26 11:26:02.000000000 -0700
  51.230 +@@ -1212,7 +1212,7 @@ int tpm_unmarshal_TPM_STANY_FLAGS(BYTE *
  51.231 + 
  51.232 + int tpm_marshal_RSA(BYTE **ptr, UINT32 *length, rsa_private_key_t *v)
  51.233 + {
  51.234 +-  UINT32 m_len, e_len, q_len;
  51.235 ++  size_t m_len, e_len, q_len;
  51.236 +   if (*length < sizeof_RSA((*v))) return -1;
  51.237 +   if (v->size > 0) {
  51.238 +     rsa_export_modulus(v, &(*ptr)[6], &m_len);
  51.239 +diff -uprN tpm_emulator-0.3/tpm/tpm_owner.c tpm_emulator-0.3-x86_64/tpm/tpm_owner.c
  51.240 +--- tpm_emulator-0.3/tpm/tpm_owner.c	2006-01-10 04:21:45.000000000 -0800
  51.241 ++++ tpm_emulator-0.3-x86_64/tpm/tpm_owner.c	2006-05-26 11:26:02.000000000 -0700
  51.242 +@@ -108,7 +108,7 @@ TPM_RESULT TPM_TakeOwnership(TPM_PROTOCO
  51.243 +   TPM_RESULT res;
  51.244 +   rsa_private_key_t *ek = &tpmData.permanent.data.endorsementKey;
  51.245 +   TPM_KEY_DATA *srk = &tpmData.permanent.data.srk;
  51.246 +-  UINT32 buf_size = ek->size >> 3;
  51.247 ++  size_t buf_size = ek->size >> 3, key_length; 
  51.248 +   BYTE buf[buf_size];
  51.249 + 
  51.250 +   info("TPM_TakeOwnership()");
  51.251 +@@ -172,7 +172,8 @@ TPM_RESULT TPM_TakeOwnership(TPM_PROTOCO
  51.252 +     return TPM_FAIL;
  51.253 +   }
  51.254 +   rsa_export_modulus(&srk->key, srkPub->pubKey.key,
  51.255 +-    &srkPub->pubKey.keyLength);
  51.256 ++		     &key_length);
  51.257 ++  srkPub->pubKey.keyLength = (UINT32) key_length;
  51.258 +   /* setup tpmProof and set state to owned */
  51.259 +   tpm_get_random_bytes(tpmData.permanent.data.tpmProof.nonce, 
  51.260 +     sizeof(tpmData.permanent.data.tpmProof.nonce));
  51.261 +diff -uprN tpm_emulator-0.3/tpm/tpm_storage.c tpm_emulator-0.3-x86_64/tpm/tpm_storage.c
  51.262 +--- tpm_emulator-0.3/tpm/tpm_storage.c	2006-01-10 04:21:45.000000000 -0800
  51.263 ++++ tpm_emulator-0.3-x86_64/tpm/tpm_storage.c	2006-05-26 14:33:18.000000000 -0700
  51.264 +@@ -58,6 +58,7 @@ int encrypt_sealed_data(TPM_KEY_DATA *ke
  51.265 +                         BYTE *enc, UINT32 *enc_size)
  51.266 + {
  51.267 +   UINT32 len;
  51.268 ++  size_t enc_size32 = *enc_size;
  51.269 +   BYTE *buf, *ptr;
  51.270 +   rsa_public_key_t pub_key;
  51.271 +   int scheme;
  51.272 +@@ -72,7 +73,7 @@ int encrypt_sealed_data(TPM_KEY_DATA *ke
  51.273 +   if (buf == NULL
  51.274 +       || tpm_marshal_TPM_SEALED_DATA(&ptr, &len, seal)
  51.275 +       || rsa_encrypt(&pub_key, scheme, buf, sizeof_TPM_SEALED_DATA((*seal)),
  51.276 +-                     enc, enc_size)) {
  51.277 ++                     enc, &enc_size32)) {
  51.278 +     tpm_free(buf);
  51.279 +     rsa_release_public_key(&pub_key);
  51.280 +     return -1;
  51.281 +@@ -85,7 +86,8 @@ int encrypt_sealed_data(TPM_KEY_DATA *ke
  51.282 + int decrypt_sealed_data(TPM_KEY_DATA *key, BYTE *enc, UINT32 enc_size,
  51.283 +                         TPM_SEALED_DATA *seal, BYTE **buf) 
  51.284 + {
  51.285 +-  UINT32 len;
  51.286 ++  size_t len;
  51.287 ++  UINT32 len32;
  51.288 +   BYTE *ptr;
  51.289 +   int scheme;
  51.290 +   switch (key->encScheme) {
  51.291 +@@ -96,8 +98,12 @@ int decrypt_sealed_data(TPM_KEY_DATA *ke
  51.292 +   len = enc_size;
  51.293 +   *buf = ptr = tpm_malloc(len);
  51.294 +   if (*buf == NULL
  51.295 +-      || rsa_decrypt(&key->key, scheme, enc, enc_size, *buf, &len)
  51.296 +-      || tpm_unmarshal_TPM_SEALED_DATA(&ptr, &len, seal)) {
  51.297 ++      || rsa_decrypt(&key->key, scheme, enc, enc_size, *buf, &len) ){
  51.298 ++    tpm_free(*buf);
  51.299 ++    return -1;
  51.300 ++  }
  51.301 ++  len32 = len;
  51.302 ++  if (tpm_unmarshal_TPM_SEALED_DATA(&ptr, &len32, seal)) {
  51.303 +     tpm_free(*buf);
  51.304 +     return -1;
  51.305 +   }
  51.306 +@@ -237,11 +243,12 @@ TPM_RESULT TPM_Unseal(TPM_KEY_HANDLE par
  51.307 + 
  51.308 + TPM_RESULT TPM_UnBind(TPM_KEY_HANDLE keyHandle, UINT32 inDataSize,
  51.309 +                       BYTE *inData, TPM_AUTH *auth1, 
  51.310 +-                      UINT32 *outDataSize, BYTE **outData)
  51.311 ++                      UINT32 *outDataSize32, BYTE **outData)
  51.312 + {
  51.313 +   TPM_RESULT res;
  51.314 +   TPM_KEY_DATA *key;
  51.315 +   int scheme;
  51.316 ++  size_t outDataSize;
  51.317 +   info("TPM_UnBind()");
  51.318 +   /* get key */
  51.319 +   key = tpm_get_key(keyHandle);
  51.320 +@@ -258,8 +265,8 @@ TPM_RESULT TPM_UnBind(TPM_KEY_HANDLE key
  51.321 +   /* the size of the input data muss be greater than zero */
  51.322 +   if (inDataSize == 0) return TPM_BAD_PARAMETER;
  51.323 +   /* decrypt data */
  51.324 +-  *outDataSize = inDataSize;
  51.325 +-  *outData = tpm_malloc(*outDataSize);
  51.326 ++  outDataSize = inDataSize;
  51.327 ++  *outData = tpm_malloc(outDataSize);
  51.328 +   if (*outData == NULL) return TPM_FAIL;
  51.329 +   switch (key->encScheme) {
  51.330 +     case TPM_ES_RSAESOAEP_SHA1_MGF1: scheme = RSA_ES_OAEP_SHA1; break;
  51.331 +@@ -267,20 +274,21 @@ TPM_RESULT TPM_UnBind(TPM_KEY_HANDLE key
  51.332 +     default: tpm_free(*outData); return TPM_DECRYPT_ERROR;
  51.333 +   }
  51.334 +   if (rsa_decrypt(&key->key, scheme, inData, inDataSize, 
  51.335 +-      *outData, outDataSize)) {
  51.336 ++      *outData, &outDataSize)) {
  51.337 +     tpm_free(*outData);
  51.338 +     return TPM_DECRYPT_ERROR;
  51.339 +   }
  51.340 +   /* verify data if it is of type TPM_BOUND_DATA */
  51.341 +   if (key->encScheme == TPM_ES_RSAESOAEP_SHA1_MGF1 
  51.342 +       || key->keyUsage != TPM_KEY_LEGACY) {
  51.343 +-    if (*outDataSize < 5 || memcmp(*outData, "\x01\x01\00\x00\x02", 5) != 0) {
  51.344 ++    if (outDataSize < 5 || memcmp(*outData, "\x01\x01\00\x00\x02", 5) != 0) {
  51.345 +       tpm_free(*outData);
  51.346 +       return TPM_DECRYPT_ERROR;
  51.347 +     }
  51.348 +-    *outDataSize -= 5;
  51.349 +-    memmove(*outData, &(*outData)[5], *outDataSize);
  51.350 ++    outDataSize -= 5;
  51.351 ++    memmove(*outData, &(*outData)[5], outDataSize);
  51.352 +   }
  51.353 ++  *outDataSize32 = (UINT32) outDataSize;
  51.354 +   return TPM_SUCCESS;
  51.355 + }
  51.356 + 
  51.357 +@@ -311,12 +319,13 @@ static int verify_key_digest(TPM_KEY *ke
  51.358 + }
  51.359 + 
  51.360 + int encrypt_private_key(TPM_KEY_DATA *key, TPM_STORE_ASYMKEY *store,
  51.361 +-                        BYTE *enc, UINT32 *enc_size)
  51.362 ++                        BYTE *enc, UINT32 *enc_size32)
  51.363 + {
  51.364 +   UINT32 len;
  51.365 +   BYTE *buf, *ptr;
  51.366 +   rsa_public_key_t pub_key;
  51.367 +   int scheme;
  51.368 ++  size_t enc_size;
  51.369 +   switch (key->encScheme) {
  51.370 +     case TPM_ES_RSAESOAEP_SHA1_MGF1: scheme = RSA_ES_OAEP_SHA1; break;
  51.371 +     case TPM_ES_RSAESPKCSv15: scheme = RSA_ES_PKCSV15; break;
  51.372 +@@ -328,11 +337,12 @@ int encrypt_private_key(TPM_KEY_DATA *ke
  51.373 +   if (buf == NULL
  51.374 +       || tpm_marshal_TPM_STORE_ASYMKEY(&ptr, &len, store)
  51.375 +       || rsa_encrypt(&pub_key, scheme, buf, sizeof_TPM_STORE_ASYMKEY((*store)),
  51.376 +-                     enc, enc_size)) {
  51.377 ++                     enc, &enc_size)) {
  51.378 +     tpm_free(buf);
  51.379 +     rsa_release_public_key(&pub_key);
  51.380 +     return -1;
  51.381 +   }
  51.382 ++  *enc_size32 = (UINT32) enc_size;
  51.383 +   tpm_free(buf);
  51.384 +   rsa_release_public_key(&pub_key);
  51.385 +   return 0;
  51.386 +@@ -341,7 +351,8 @@ int encrypt_private_key(TPM_KEY_DATA *ke
  51.387 + int decrypt_private_key(TPM_KEY_DATA *key, BYTE *enc, UINT32 enc_size, 
  51.388 +                         TPM_STORE_ASYMKEY *store, BYTE **buf) 
  51.389 + {
  51.390 +-  UINT32 len;
  51.391 ++  UINT32 len32;
  51.392 ++  size_t len;
  51.393 +   BYTE *ptr;
  51.394 +   int scheme;
  51.395 +   switch (key->encScheme) {
  51.396 +@@ -352,8 +363,12 @@ int decrypt_private_key(TPM_KEY_DATA *ke
  51.397 +   len = enc_size;
  51.398 +   *buf = ptr = tpm_malloc(len);
  51.399 +   if (*buf == NULL
  51.400 +-      || rsa_decrypt(&key->key, scheme, enc, enc_size, *buf, &len)
  51.401 +-      || tpm_unmarshal_TPM_STORE_ASYMKEY(&ptr, &len, store)) {
  51.402 ++      || rsa_decrypt(&key->key, scheme, enc, enc_size, *buf, &len) ) {
  51.403 ++    tpm_free(*buf);
  51.404 ++    return -1;
  51.405 ++  }
  51.406 ++  len32 = (UINT32) len;
  51.407 ++  if (tpm_unmarshal_TPM_STORE_ASYMKEY(&ptr, &len32, store)) {  
  51.408 +     tpm_free(*buf);
  51.409 +     return -1;
  51.410 +   }
  51.411 +@@ -371,7 +386,7 @@ TPM_RESULT TPM_CreateWrapKey(TPM_KEY_HAN
  51.412 +   TPM_SESSION_DATA *session;
  51.413 +   TPM_STORE_ASYMKEY store;
  51.414 +   rsa_private_key_t rsa;
  51.415 +-  UINT32 key_length;
  51.416 ++  size_t key_length;
  51.417 + 
  51.418 +   info("TPM_CreateWrapKey()");
  51.419 +   /* get parent key */
  51.420 +@@ -428,11 +443,11 @@ TPM_RESULT TPM_CreateWrapKey(TPM_KEY_HAN
  51.421 +   }
  51.422 +   if (compute_key_digest(wrappedKey, &store.pubDataDigest)) return TPM_FAIL;
  51.423 +   /* generate key and store it */
  51.424 +-  key_length = keyInfo->algorithmParms.parms.rsa.keyLength;
  51.425 +-  if (rsa_generate_key(&rsa, key_length)) return TPM_FAIL;
  51.426 +-  wrappedKey->pubKey.keyLength = key_length >> 3;
  51.427 ++  if (rsa_generate_key(&rsa, keyInfo->algorithmParms.parms.rsa.keyLength)) 
  51.428 ++    return TPM_FAIL;
  51.429 ++  wrappedKey->pubKey.keyLength = keyInfo->algorithmParms.parms.rsa.keyLength >> 3;
  51.430 +   wrappedKey->pubKey.key = tpm_malloc(wrappedKey->pubKey.keyLength);
  51.431 +-  store.privKey.keyLength = key_length >> 4;
  51.432 ++  store.privKey.keyLength = keyInfo->algorithmParms.parms.rsa.keyLength >> 4;
  51.433 +   store.privKey.key = tpm_malloc(store.privKey.keyLength);
  51.434 +   wrappedKey->encDataSize = parent->key.size >> 3;
  51.435 +   wrappedKey->encData = tpm_malloc(wrappedKey->encDataSize);
  51.436 +@@ -444,9 +459,11 @@ TPM_RESULT TPM_CreateWrapKey(TPM_KEY_HAN
  51.437 +     tpm_free(wrappedKey->encData);
  51.438 +     return TPM_FAIL;
  51.439 +   }
  51.440 +-  rsa_export_modulus(&rsa, wrappedKey->pubKey.key, 
  51.441 +-    &wrappedKey->pubKey.keyLength);
  51.442 +-  rsa_export_prime1(&rsa, store.privKey.key, &store.privKey.keyLength);
  51.443 ++  rsa_export_modulus(&rsa, wrappedKey->pubKey.key,
  51.444 ++		     &key_length);
  51.445 ++  wrappedKey->pubKey.keyLength = (UINT32) key_length;
  51.446 ++  rsa_export_prime1(&rsa, store.privKey.key, &key_length);
  51.447 ++  store.privKey.keyLength = (UINT32) key_length;
  51.448 +   rsa_release_private_key(&rsa);
  51.449 +   /* encrypt private key data */
  51.450 +   if (encrypt_private_key(parent, &store, wrappedKey->encData, 
  51.451 +@@ -567,6 +584,7 @@ TPM_RESULT TPM_LoadKey2(TPM_KEY_HANDLE p
  51.452 + 
  51.453 + int tpm_setup_key_parms(TPM_KEY_DATA *key, TPM_KEY_PARMS *parms)
  51.454 + {
  51.455 ++  size_t key_length;
  51.456 +   parms->algorithmID = TPM_ALG_RSA;
  51.457 +   parms->encScheme = key->encScheme;
  51.458 +   parms->sigScheme = key->sigScheme;
  51.459 +@@ -576,7 +594,8 @@ int tpm_setup_key_parms(TPM_KEY_DATA *ke
  51.460 +   parms->parms.rsa.exponent = tpm_malloc(parms->parms.rsa.exponentSize);
  51.461 +   if (parms->parms.rsa.exponent == NULL) return -1;
  51.462 +   rsa_export_exponent(&key->key, parms->parms.rsa.exponent,
  51.463 +-    &parms->parms.rsa.exponentSize);
  51.464 ++    &key_length);
  51.465 ++  parms->parms.rsa.exponentSize = (UINT32) key_length;
  51.466 +   parms->parmSize = 12 + parms->parms.rsa.exponentSize;
  51.467 +   return 0;
  51.468 + }
  51.469 +@@ -587,6 +606,7 @@ TPM_RESULT TPM_GetPubKey(TPM_KEY_HANDLE 
  51.470 +   TPM_RESULT res;
  51.471 +   TPM_KEY_DATA *key;
  51.472 +   TPM_DIGEST digest;
  51.473 ++  size_t key_length;
  51.474 +   info("TPM_GetPubKey()");
  51.475 +   /* get key */
  51.476 +   if (keyHandle == TPM_KH_SRK) return TPM_BAD_PARAMETER;
  51.477 +@@ -614,8 +634,8 @@ TPM_RESULT TPM_GetPubKey(TPM_KEY_HANDLE 
  51.478 +   pubKey->pubKey.keyLength = key->key.size >> 3;
  51.479 +   pubKey->pubKey.key = tpm_malloc(pubKey->pubKey.keyLength);
  51.480 +   if (pubKey->pubKey.key == NULL) return TPM_FAIL;
  51.481 +-  rsa_export_modulus(&key->key, pubKey->pubKey.key, 
  51.482 +-    &pubKey->pubKey.keyLength);
  51.483 ++  rsa_export_modulus(&key->key, pubKey->pubKey.key, &key_length); 
  51.484 ++  pubKey->pubKey.keyLength = (UINT32) key_length;
  51.485 +   if (tpm_setup_key_parms(key, &pubKey->algorithmParms) != 0) {
  51.486 +     tpm_free(pubKey->pubKey.key);
  51.487 +     return TPM_FAIL;
    52.1 --- a/tools/vtpm/vtpm.patch	Wed May 31 11:30:07 2006 -0600
    52.2 +++ b/tools/vtpm/vtpm.patch	Wed May 31 13:05:21 2006 -0600
    52.3 @@ -1,23 +1,24 @@
    52.4 -diff -uprN orig/tpm_emulator-0.2-x86_64/AUTHORS vtpm/AUTHORS
    52.5 ---- orig/tpm_emulator-0.2-x86_64/AUTHORS	2005-08-15 00:58:57.000000000 -0700
    52.6 -+++ vtpm/AUTHORS	2006-05-17 09:31:11.000000000 -0700
    52.7 -@@ -1 +1,2 @@
    52.8 +diff -uprN orig/tpm_emulator-0.3-x86_64/AUTHORS vtpm/AUTHORS
    52.9 +--- orig/tpm_emulator-0.3-x86_64/AUTHORS	2006-01-10 04:21:45.000000000 -0800
   52.10 ++++ vtpm/AUTHORS	2006-05-30 12:23:26.000000000 -0700
   52.11 +@@ -1,2 +1,3 @@
   52.12   Mario Strasser <mast@gmx.net>
   52.13 -+INTEL Corp <>
   52.14 -diff -uprN orig/tpm_emulator-0.2-x86_64/ChangeLog vtpm/ChangeLog
   52.15 ---- orig/tpm_emulator-0.2-x86_64/ChangeLog	2005-08-15 00:58:57.000000000 -0700
   52.16 -+++ vtpm/ChangeLog	2006-05-17 09:31:11.000000000 -0700
   52.17 + Heiko Stamer <stamer@gaos.org> [DAA]
   52.18 ++INTEL Corp <> [VTPM Extensions]
   52.19 +diff -uprN orig/tpm_emulator-0.3-x86_64/ChangeLog vtpm/ChangeLog
   52.20 +--- orig/tpm_emulator-0.3-x86_64/ChangeLog	2006-01-10 04:21:45.000000000 -0800
   52.21 ++++ vtpm/ChangeLog	2006-05-30 12:23:26.000000000 -0700
   52.22  @@ -1,3 +1,7 @@
   52.23  +2005-08-16 Intel Corp
   52.24 -+	Moved module out of kernel to run as a ring 3 app
   52.25 -+	Modified save_to_file and load_from_file to call a xen backend driver to call a VTPM manager
   52.26 ++	* Moved module out of kernel to run as a ring 3 app
   52.27 ++	* Modified save_to_file and load_from_file to call a xen backend driver to call a VTPM manager
   52.28  +
   52.29 - 2005-08-15  Mario Strasser <mast@gmx.net>
   52.30 - 	* all: some typos corrected
   52.31 - 	* tpm_integrity.c: bug in TPM_Extend fixed
   52.32 -diff -uprN orig/tpm_emulator-0.2-x86_64/crypto/gmp_kernel_wrapper.c vtpm/crypto/gmp_kernel_wrapper.c
   52.33 ---- orig/tpm_emulator-0.2-x86_64/crypto/gmp_kernel_wrapper.c	2006-05-17 09:34:13.000000000 -0700
   52.34 -+++ vtpm/crypto/gmp_kernel_wrapper.c	2006-05-17 09:31:11.000000000 -0700
   52.35 + 2005-12-24  Mario Strasser <mast@gmx.net>
   52.36 + 	* tpm_transport.c, tpm_marshalling.c, tpm_structures.h:
   52.37 + 		Transport session functionality added
   52.38 +diff -uprN orig/tpm_emulator-0.3-x86_64/crypto/gmp_kernel_wrapper.c vtpm/crypto/gmp_kernel_wrapper.c
   52.39 +--- orig/tpm_emulator-0.3-x86_64/crypto/gmp_kernel_wrapper.c	2006-05-30 12:28:02.000000000 -0700
   52.40 ++++ vtpm/crypto/gmp_kernel_wrapper.c	2006-05-30 12:23:26.000000000 -0700
   52.41  @@ -1,5 +1,6 @@
   52.42   /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
   52.43    * Copyright (C) 2004 Mario Strasser <mast@gmx.net>,
   52.44 @@ -77,9 +78,9 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
   52.45     }
   52.46   }
   52.47   
   52.48 -diff -uprN orig/tpm_emulator-0.2-x86_64/crypto/rsa.c vtpm/crypto/rsa.c
   52.49 ---- orig/tpm_emulator-0.2-x86_64/crypto/rsa.c	2005-08-15 00:58:57.000000000 -0700
   52.50 -+++ vtpm/crypto/rsa.c	2006-05-17 09:31:11.000000000 -0700
   52.51 +diff -uprN orig/tpm_emulator-0.3-x86_64/crypto/rsa.c vtpm/crypto/rsa.c
   52.52 +--- orig/tpm_emulator-0.3-x86_64/crypto/rsa.c	2006-01-10 04:21:45.000000000 -0800
   52.53 ++++ vtpm/crypto/rsa.c	2006-05-30 12:23:26.000000000 -0700
   52.54  @@ -1,5 +1,6 @@
   52.55   /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
   52.56    * Copyright (C) 2004 Mario Strasser <mast@gmx.net>,
   52.57 @@ -87,7 +88,7 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
   52.58    *
   52.59    * This module is free software; you can redistribute it and/or modify
   52.60    * it under the terms of the GNU General Public License as published
   52.61 -@@ -363,7 +364,7 @@ static int encode_message(int type, uint
   52.62 +@@ -381,7 +382,7 @@ static int encode_message(int type, uint
   52.63         msg[0] = 0x00;
   52.64         get_random_bytes(&msg[1], SHA1_DIGEST_LENGTH);
   52.65         sha1_init(&ctx);
   52.66 @@ -96,7 +97,7 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
   52.67         sha1_final(&ctx, &msg[1 + SHA1_DIGEST_LENGTH]);
   52.68         memset(&msg[1 + 2 * SHA1_DIGEST_LENGTH], 0x00, 
   52.69           msg_len - data_len - 2 * SHA1_DIGEST_LENGTH - 2);
   52.70 -@@ -411,7 +412,7 @@ static int decode_message(int type, uint
   52.71 +@@ -429,7 +430,7 @@ static int decode_message(int type, uint
   52.72         mask_generation(&msg[1], SHA1_DIGEST_LENGTH,
   52.73           &msg[1 + SHA1_DIGEST_LENGTH], msg_len - SHA1_DIGEST_LENGTH - 1);
   52.74         sha1_init(&ctx);
   52.75 @@ -105,10 +106,10 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
   52.76         sha1_final(&ctx, &msg[1]);
   52.77         if (memcmp(&msg[1], &msg[1 + SHA1_DIGEST_LENGTH], 
   52.78             SHA1_DIGEST_LENGTH) != 0) return -1;
   52.79 -diff -uprN orig/tpm_emulator-0.2-x86_64/linux_module.c vtpm/linux_module.c
   52.80 ---- orig/tpm_emulator-0.2-x86_64/linux_module.c	2006-05-17 09:34:13.000000000 -0700
   52.81 +diff -uprN orig/tpm_emulator-0.3-x86_64/linux_module.c vtpm/linux_module.c
   52.82 +--- orig/tpm_emulator-0.3-x86_64/linux_module.c	2006-05-30 12:28:02.000000000 -0700
   52.83  +++ vtpm/linux_module.c	1969-12-31 16:00:00.000000000 -0800
   52.84 -@@ -1,163 +0,0 @@
   52.85 +@@ -1,194 +0,0 @@
   52.86  -/* Software-Based Trusted Platform Module (TPM) Emulator for Linux 
   52.87  - * Copyright (C) 2004 Mario Strasser <mast@gmx.net>,
   52.88  - *
   52.89 @@ -122,7 +123,7 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
   52.90  - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
   52.91  - * GNU General Public License for more details.
   52.92  - *
   52.93 -- * $Id: linux_module.c 19 2005-05-18 08:29:37Z mast $
   52.94 +- * $Id: linux_module.c 76 2006-01-02 22:17:58Z hstamer $
   52.95  - */
   52.96  -
   52.97  -#include <linux/module.h>
   52.98 @@ -140,11 +141,11 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
   52.99  -
  52.100  -/* module startup parameters */
  52.101  -char *startup = "save";
  52.102 --MODULE_PARM(startup, "s");
  52.103 +-module_param(startup, charp, 0444);
  52.104  -MODULE_PARM_DESC(startup, " Sets the startup mode of the TPM. "
  52.105  -  "Possible values are 'clear', 'save' (default) and 'deactivated.");
  52.106 --char *storage_file = "/var/tpm/tpm_emulator-1.2.0.1";
  52.107 --MODULE_PARM(storage_file, "s");
  52.108 +-char *storage_file = "/var/tpm/tpm_emulator-1.2.0.2";
  52.109 +-module_param(storage_file, charp, 0644);
  52.110  -MODULE_PARM_DESC(storage_file, " Sets the persistent-data storage " 
  52.111  -  "file of the TPM.");
  52.112  -
  52.113 @@ -172,6 +173,12 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
  52.114  -{
  52.115  -  debug("%s()", __FUNCTION__);
  52.116  -  clear_bit(STATE_IS_OPEN, (void*)&module_state);
  52.117 +-  down(&tpm_mutex);
  52.118 +-  if (tpm_response.data != NULL) {
  52.119 +-    kfree(tpm_response.data);
  52.120 +-    tpm_response.data = NULL;
  52.121 +-  }
  52.122 +-  up(&tpm_mutex);
  52.123  -  return 0;
  52.124  -}
  52.125  -
  52.126 @@ -183,6 +190,10 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
  52.127  -    count = min(count, (size_t)tpm_response.size - (size_t)*ppos);
  52.128  -    count -= copy_to_user(buf, &tpm_response.data[*ppos], count);
  52.129  -    *ppos += count;
  52.130 +-    if ((size_t)tpm_response.size == (size_t)*ppos) {
  52.131 +-      kfree(tpm_response.data);
  52.132 +-      tpm_response.data = NULL;
  52.133 +-    }
  52.134  -  } else {
  52.135  -    count = 0;
  52.136  -  }
  52.137 @@ -205,9 +216,29 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
  52.138  -  return count;
  52.139  -}
  52.140  -
  52.141 +-#define TPMIOC_CANCEL   _IO('T', 0x00)
  52.142 +-#define TPMIOC_TRANSMIT _IO('T', 0x01)
  52.143 +-
  52.144  -static int tpm_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
  52.145  -{
  52.146 --  debug("%s(%d, %ld)", __FUNCTION__, cmd, arg);
  52.147 +-  debug("%s(%d, %p)", __FUNCTION__, cmd, (char*)arg);
  52.148 +-  if (cmd == TPMIOC_TRANSMIT) {
  52.149 +-    uint32_t count = ntohl(*(uint32_t*)(arg + 2));
  52.150 +-    down(&tpm_mutex);
  52.151 +-    if (tpm_response.data != NULL) kfree(tpm_response.data);
  52.152 +-    if (tpm_handle_command((char*)arg, count, &tpm_response.data,
  52.153 +-                           &tpm_response.size) == 0) {
  52.154 +-      tpm_response.size -= copy_to_user((char*)arg, tpm_response.data,
  52.155 +-                            tpm_response.size);
  52.156 +-      kfree(tpm_response.data);
  52.157 +-      tpm_response.data = NULL;
  52.158 +-    } else {
  52.159 +-      tpm_response.size = 0;
  52.160 +-      tpm_response.data = NULL;
  52.161 +-    }
  52.162 +-    up(&tpm_mutex);
  52.163 +-    return tpm_response.size;
  52.164 +-  }
  52.165  -  return -1;
  52.166  -}
  52.167  -
  52.168 @@ -240,7 +271,7 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
  52.169  -  /* initialize TPM emulator */
  52.170  -  if (!strcmp(startup, "clear")) {
  52.171  -    tpm_emulator_init(1);
  52.172 --  } else if (!strcmp(startup, "save")) { 
  52.173 +-  } else if (!strcmp(startup, "save")) {
  52.174  -    tpm_emulator_init(2);
  52.175  -  } else if (!strcmp(startup, "deactivated")) {
  52.176  -    tpm_emulator_init(3);
  52.177 @@ -257,6 +288,7 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
  52.178  -{
  52.179  -  tpm_emulator_shutdown();
  52.180  -  misc_deregister(&tpm_dev);
  52.181 +-  if (tpm_response.data != NULL) kfree(tpm_response.data);
  52.182  -}
  52.183  -
  52.184  -module_init(init_tpm_module);
  52.185 @@ -264,7 +296,7 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
  52.186  -
  52.187  -uint64_t tpm_get_ticks(void)
  52.188  -{
  52.189 --  static struct timespec old_time = {0, 0}; 
  52.190 +-  static struct timespec old_time = {0, 0};
  52.191  -  struct timespec new_time = current_kernel_time();
  52.192  -  uint64_t ticks = (uint64_t)(old_time.tv_sec - new_time.tv_sec) * 1000000
  52.193  -                   + (old_time.tv_nsec - new_time.tv_nsec) / 1000;
  52.194 @@ -272,9 +304,9 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
  52.195  -  return (ticks > 0) ? ticks : 1;
  52.196  -}
  52.197  -
  52.198 -diff -uprN orig/tpm_emulator-0.2-x86_64/linux_module.h vtpm/linux_module.h
  52.199 ---- orig/tpm_emulator-0.2-x86_64/linux_module.h	2006-05-17 09:34:13.000000000 -0700
  52.200 -+++ vtpm/linux_module.h	2006-05-17 09:31:11.000000000 -0700
  52.201 +diff -uprN orig/tpm_emulator-0.3-x86_64/linux_module.h vtpm/linux_module.h
  52.202 +--- orig/tpm_emulator-0.3-x86_64/linux_module.h	2006-05-30 12:28:02.000000000 -0700
  52.203 ++++ vtpm/linux_module.h	2006-05-30 12:23:26.000000000 -0700
  52.204  @@ -1,5 +1,6 @@
  52.205   /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
  52.206    * Copyright (C) 2004 Mario Strasser <mast@gmx.net>,
  52.207 @@ -374,15 +406,15 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
  52.208   #define BE16_TO_CPU(x) __be16_to_cpu(x)
  52.209   #define LE16_TO_CPU(x) __le16_to_cpu(x)
  52.210   
  52.211 -diff -uprN orig/tpm_emulator-0.2-x86_64/Makefile vtpm/Makefile
  52.212 ---- orig/tpm_emulator-0.2-x86_64/Makefile	2006-05-17 09:34:13.000000000 -0700
  52.213 -+++ vtpm/Makefile	2006-05-17 09:31:11.000000000 -0700
  52.214 +diff -uprN orig/tpm_emulator-0.3-x86_64/Makefile vtpm/Makefile
  52.215 +--- orig/tpm_emulator-0.3-x86_64/Makefile	2006-05-30 12:28:02.000000000 -0700
  52.216 ++++ vtpm/Makefile	2006-05-30 12:23:26.000000000 -0700
  52.217  @@ -1,22 +1,31 @@
  52.218   # Software-Based Trusted Platform Module (TPM) Emulator for Linux
  52.219   # Copyright (C) 2004 Mario Strasser <mast@gmx.net>
  52.220 -+# Copyright (C) 2005 INTEL Corp.
  52.221 ++# Copyright (C) 2006 INTEL Corp.
  52.222   #
  52.223 - # $Id: Makefile 10 2005-04-26 20:59:50Z mast $
  52.224 + # $Id: Makefile 69 2005-12-13 12:55:52Z mast $
  52.225   
  52.226  -# kernel settings
  52.227  -KERNEL_RELEASE := $(shell uname -r)
  52.228 @@ -394,11 +426,11 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
  52.229  -MODULE_NAME    := tpm_emulator
  52.230  +BIN            := vtpmd
  52.231   VERSION_MAJOR  := 0
  52.232 - VERSION_MINOR  := 2
  52.233 + VERSION_MINOR  := 3
  52.234   VERSION_BUILD  := $(shell date +"%s")
  52.235   
  52.236  -# enable/disable DEBUG messages
  52.237 --EXTRA_CFLAGS   += -DDEBUG -g  
  52.238 +-EXTRA_CFLAGS   += -Wall -DDEBUG -g  
  52.239  +# Installation program and options
  52.240  +INSTALL         = install
  52.241  +INSTALL_PROG    = $(INSTALL) -m0755
  52.242 @@ -468,10 +500,10 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
  52.243   
  52.244   $(src)/crypto/libgmp.a:
  52.245   	test -f $(src)/crypto/libgmp.a || ln -s $(GMP_LIB) $(src)/crypto/libgmp.a
  52.246 -diff -uprN orig/tpm_emulator-0.2-x86_64/README vtpm/README
  52.247 ---- orig/tpm_emulator-0.2-x86_64/README	2006-05-17 09:34:13.000000000 -0700
  52.248 -+++ vtpm/README	2006-05-17 09:31:11.000000000 -0700
  52.249 -@@ -13,7 +13,8 @@ $Id: README 8 2005-01-25 21:11:45Z jmoli
  52.250 +diff -uprN orig/tpm_emulator-0.3-x86_64/README vtpm/README
  52.251 +--- orig/tpm_emulator-0.3-x86_64/README	2006-05-30 12:28:02.000000000 -0700
  52.252 ++++ vtpm/README	2006-05-30 12:23:26.000000000 -0700
  52.253 +@@ -13,7 +13,8 @@ $Id: README 78 2006-01-07 10:45:39Z mast
  52.254   Copyright
  52.255   --------------------------------------------------------------------------
  52.256   Copyright (C) 2004 Mario Strasser <mast@gmx.net> and Swiss Federal 
  52.257 @@ -481,9 +513,9 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
  52.258                 
  52.259   This program is free software; you can redistribute it and/or modify
  52.260   it under the terms of the GNU General Public License as published by
  52.261 -diff -uprN orig/tpm_emulator-0.2-x86_64/tpm/tpm_audit.c vtpm/tpm/tpm_audit.c
  52.262 ---- orig/tpm_emulator-0.2-x86_64/tpm/tpm_audit.c	2005-08-15 00:58:57.000000000 -0700
  52.263 -+++ vtpm/tpm/tpm_audit.c	2006-05-17 09:31:11.000000000 -0700
  52.264 +diff -uprN orig/tpm_emulator-0.3-x86_64/tpm/tpm_audit.c vtpm/tpm/tpm_audit.c
  52.265 +--- orig/tpm_emulator-0.3-x86_64/tpm/tpm_audit.c	2006-01-10 04:21:45.000000000 -0800
  52.266 ++++ vtpm/tpm/tpm_audit.c	2006-05-30 12:23:26.000000000 -0700
  52.267  @@ -1,6 +1,7 @@
  52.268   /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
  52.269    * Copyright (C) 2004 Mario Strasser <mast@gmx.net>,
  52.270 @@ -546,9 +578,9 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
  52.271     return TPM_SUCCESS;
  52.272   }
  52.273  -
  52.274 -diff -uprN orig/tpm_emulator-0.2-x86_64/tpm/tpm_authorization.c vtpm/tpm/tpm_authorization.c
  52.275 ---- orig/tpm_emulator-0.2-x86_64/tpm/tpm_authorization.c	2005-08-15 00:58:57.000000000 -0700
  52.276 -+++ vtpm/tpm/tpm_authorization.c	2006-05-17 09:31:11.000000000 -0700
  52.277 +diff -uprN orig/tpm_emulator-0.3-x86_64/tpm/tpm_authorization.c vtpm/tpm/tpm_authorization.c
  52.278 +--- orig/tpm_emulator-0.3-x86_64/tpm/tpm_authorization.c	2006-01-10 04:21:45.000000000 -0800
  52.279 ++++ vtpm/tpm/tpm_authorization.c	2006-05-30 12:23:26.000000000 -0700
  52.280  @@ -1,6 +1,7 @@
  52.281   /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
  52.282    * Copyright (C) 2004 Mario Strasser <mast@gmx.net>,
  52.283 @@ -557,7 +589,7 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
  52.284    *
  52.285    * This module is free software; you can redistribute it and/or modify
  52.286    * it under the terms of the GNU General Public License as published
  52.287 -@@ -268,7 +269,7 @@ TPM_RESULT tpm_verify_auth(TPM_AUTH *aut
  52.288 +@@ -279,7 +280,7 @@ TPM_RESULT tpm_verify_auth(TPM_AUTH *aut
  52.289   {
  52.290     hmac_ctx_t ctx;
  52.291     TPM_SESSION_DATA *session;
  52.292 @@ -565,16 +597,10 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
  52.293  +  UINT32 auth_handle = CPU_TO_BE32(auth->authHandle);
  52.294     
  52.295     info("tpm_verify_auth(%08x)", auth->authHandle);
  52.296 -   /* get dedicated authorization session */
  52.297 -@@ -316,5 +317,3 @@ void tpm_decrypt_auth_secret(TPM_ENCAUTH
  52.298 -   for (i = 0; i < sizeof(TPM_SECRET); i++)
  52.299 -     plainAuth[i] ^= encAuth[i];
  52.300 - }
  52.301 --
  52.302 --
  52.303 -diff -uprN orig/tpm_emulator-0.2-x86_64/tpm/tpm_capability.c vtpm/tpm/tpm_capability.c
  52.304 ---- orig/tpm_emulator-0.2-x86_64/tpm/tpm_capability.c	2005-08-15 00:58:57.000000000 -0700
  52.305 -+++ vtpm/tpm/tpm_capability.c	2006-05-17 09:31:11.000000000 -0700
  52.306 +   /* get dedicated authorization or transport session */
  52.307 +diff -uprN orig/tpm_emulator-0.3-x86_64/tpm/tpm_capability.c vtpm/tpm/tpm_capability.c
  52.308 +--- orig/tpm_emulator-0.3-x86_64/tpm/tpm_capability.c	2006-01-10 04:21:45.000000000 -0800
  52.309 ++++ vtpm/tpm/tpm_capability.c	2006-05-30 12:23:26.000000000 -0700
  52.310  @@ -1,6 +1,7 @@
  52.311   /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
  52.312    * Copyright (C) 2004 Mario Strasser <mast@gmx.net>,
  52.313 @@ -583,7 +609,7 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
  52.314    *
  52.315    * This module is free software; you can redistribute it and/or modify
  52.316    * it under the terms of the GNU General Public License as published
  52.317 -@@ -398,7 +399,7 @@ TPM_RESULT TPM_GetCapability(TPM_CAPABIL
  52.318 +@@ -406,7 +407,7 @@ TPM_RESULT TPM_GetCapability(TPM_CAPABIL
  52.319   
  52.320       case TPM_CAP_KEY_HANDLE:
  52.321         debug("[TPM_CAP_KEY_HANDLE]");
  52.322 @@ -592,14 +618,14 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
  52.323         return cap_handle(4, (BYTE*)&subCapSize, respSize, resp);
  52.324   
  52.325       case TPM_CAP_CHECK_LOADED:
  52.326 -@@ -472,4 +473,3 @@ TPM_RESULT TPM_GetCapability(TPM_CAPABIL
  52.327 +@@ -480,4 +481,3 @@ TPM_RESULT TPM_GetCapability(TPM_CAPABIL
  52.328         return TPM_BAD_MODE;
  52.329     }
  52.330   }
  52.331  -
  52.332 -diff -uprN orig/tpm_emulator-0.2-x86_64/tpm/tpm_cmd_handler.c vtpm/tpm/tpm_cmd_handler.c
  52.333 ---- orig/tpm_emulator-0.2-x86_64/tpm/tpm_cmd_handler.c	2005-08-15 00:58:57.000000000 -0700
  52.334 -+++ vtpm/tpm/tpm_cmd_handler.c	2006-05-17 09:31:11.000000000 -0700
  52.335 +diff -uprN orig/tpm_emulator-0.3-x86_64/tpm/tpm_cmd_handler.c vtpm/tpm/tpm_cmd_handler.c
  52.336 +--- orig/tpm_emulator-0.3-x86_64/tpm/tpm_cmd_handler.c	2006-01-10 04:21:45.000000000 -0800
  52.337 ++++ vtpm/tpm/tpm_cmd_handler.c	2006-05-30 12:23:26.000000000 -0700
  52.338  @@ -1,6 +1,7 @@
  52.339   /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
  52.340    * Copyright (C) 2004 Mario Strasser <mast@gmx.net>,
  52.341 @@ -608,17 +634,17 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
  52.342    *
  52.343    * This module is free software; you can redistribute it and/or modify
  52.344    * it under the terms of the GNU General Public License as published
  52.345 -@@ -26,7 +27,7 @@ static void tpm_compute_in_param_digest(
  52.346 +@@ -73,7 +74,7 @@ void tpm_compute_in_param_digest(TPM_REQ
  52.347   {
  52.348     sha1_ctx_t sha1;
  52.349 -   UINT32 offset;
  52.350 +   UINT32 offset = tpm_get_param_offset(req->ordinal);
  52.351  -  UINT32 ord = cpu_to_be32(req->ordinal);
  52.352  +  UINT32 ord = CPU_TO_BE32(req->ordinal);
  52.353   
  52.354 -   /* skip all key-handles at the beginning */
  52.355 -   switch (req->ordinal) {
  52.356 -@@ -82,8 +83,8 @@ static void tpm_compute_in_param_digest(
  52.357 - static void tpm_compute_out_param_digest(TPM_COMMAND_CODE ordinal, TPM_RESPONSE *rsp)
  52.358 +   /* compute SHA1 hash */
  52.359 +   if (offset <= req->paramSize) {
  52.360 +@@ -89,8 +90,8 @@ void tpm_compute_in_param_digest(TPM_REQ
  52.361 + void tpm_compute_out_param_digest(TPM_COMMAND_CODE ordinal, TPM_RESPONSE *rsp)
  52.362   {
  52.363     sha1_ctx_t sha1;
  52.364  -  UINT32 res = cpu_to_be32(rsp->result);
  52.365 @@ -628,7 +654,7 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
  52.366   
  52.367     /* compute SHA1 hash */
  52.368     sha1_init(&sha1);
  52.369 -@@ -3081,7 +3082,7 @@ static void tpm_setup_rsp_auth(TPM_COMMA
  52.370 +@@ -3123,7 +3124,7 @@ static void tpm_setup_rsp_auth(TPM_COMMA
  52.371         hmac_update(&hmac, rsp->auth2->digest, sizeof(rsp->auth2->digest));
  52.372   #if 0
  52.373         if (tpm_get_auth(rsp->auth2->authHandle)->type == TPM_ST_OIAP) {
  52.374 @@ -637,7 +663,7 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
  52.375           hmac_update(&hmac, (BYTE*)&handle, 4);
  52.376         }
  52.377   #endif
  52.378 -@@ -3096,7 +3097,7 @@ static void tpm_setup_rsp_auth(TPM_COMMA
  52.379 +@@ -3138,7 +3139,7 @@ static void tpm_setup_rsp_auth(TPM_COMMA
  52.380         hmac_update(&hmac, rsp->auth1->digest, sizeof(rsp->auth1->digest));
  52.381   #if 0
  52.382         if (tpm_get_auth(rsp->auth1->authHandle)->type == TPM_ST_OIAP) {
  52.383 @@ -646,25 +672,20 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
  52.384           hmac_update(&hmac, (BYTE*)&handle, 4);
  52.385         }
  52.386   #endif
  52.387 -@@ -3179,7 +3180,9 @@ extern const char *tpm_error_to_string(T
  52.388 - static void tpm_execute_command(TPM_REQUEST *req, TPM_RESPONSE *rsp)
  52.389 +@@ -3221,7 +3222,9 @@ extern const char *tpm_error_to_string(T
  52.390 + void tpm_execute_command(TPM_REQUEST *req, TPM_RESPONSE *rsp)
  52.391   {
  52.392     TPM_RESULT res;
  52.393  -  
  52.394  +
  52.395 -+  req->tag = (BYTE) req->tag;  // VIN HACK!!! 
  52.396 ++  req->tag = (BYTE) req->tag;  // FIXME: Why is this here
  52.397  +
  52.398     /* setup authorisation as well as response tag and size */
  52.399     memset(rsp, 0, sizeof(*rsp));
  52.400     switch (req->tag) {
  52.401 -@@ -3878,4 +3881,3 @@ int tpm_handle_command(const uint8_t *in
  52.402 -   tpm_free(rsp.param);
  52.403 -   return 0;
  52.404 - }
  52.405 --
  52.406 -diff -uprN orig/tpm_emulator-0.2-x86_64/tpm/tpm_crypto.c vtpm/tpm/tpm_crypto.c
  52.407 ---- orig/tpm_emulator-0.2-x86_64/tpm/tpm_crypto.c	2006-05-17 09:34:13.000000000 -0700
  52.408 -+++ vtpm/tpm/tpm_crypto.c	2006-05-17 09:31:11.000000000 -0700
  52.409 +diff -uprN orig/tpm_emulator-0.3-x86_64/tpm/tpm_crypto.c vtpm/tpm/tpm_crypto.c
  52.410 +--- orig/tpm_emulator-0.3-x86_64/tpm/tpm_crypto.c	2006-05-30 12:28:02.000000000 -0700
  52.411 ++++ vtpm/tpm/tpm_crypto.c	2006-05-30 12:23:26.000000000 -0700
  52.412  @@ -1,6 +1,7 @@
  52.413   /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
  52.414    * Copyright (C) 2004 Mario Strasser <mast@gmx.net>,
  52.415 @@ -683,13 +704,170 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
  52.416       if (rsa_sign(&key->key, RSA_SSA_PKCS1_SHA1, 
  52.417           buf, areaToSignSize + 30, *sig)) {
  52.418  @@ -383,4 +384,3 @@ TPM_RESULT TPM_CertifyKey2(TPM_KEY_HANDL
  52.419 -   }  
  52.420 +   }
  52.421     return TPM_SUCCESS;
  52.422   }
  52.423  -
  52.424 -diff -uprN orig/tpm_emulator-0.2-x86_64/tpm/tpm_data.c vtpm/tpm/tpm_data.c
  52.425 ---- orig/tpm_emulator-0.2-x86_64/tpm/tpm_data.c	2006-05-17 09:34:13.000000000 -0700
  52.426 -+++ vtpm/tpm/tpm_data.c	2006-05-17 09:31:11.000000000 -0700
  52.427 +diff -uprN orig/tpm_emulator-0.3-x86_64/tpm/tpm_daa.c vtpm/tpm/tpm_daa.c
  52.428 +--- orig/tpm_emulator-0.3-x86_64/tpm/tpm_daa.c	2006-01-10 04:21:45.000000000 -0800
  52.429 ++++ vtpm/tpm/tpm_daa.c	2006-05-30 12:23:26.000000000 -0700
  52.430 +@@ -700,14 +700,14 @@ info("tested until here");
  52.431 +           sizeof(session->DAA_tpmSpecific.DAA_rekey));
  52.432 +       sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count, 
  52.433 +           sizeof(session->DAA_tpmSpecific.DAA_count));
  52.434 +-      sha1_update(&sha1, "\x00", 1);
  52.435 ++      sha1_update(&sha1, (BYTE *) "\x00", 1);
  52.436 +       sha1_final(&sha1, scratch);
  52.437 +       sha1_init(&sha1);
  52.438 +       sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_rekey, 
  52.439 +           sizeof(session->DAA_tpmSpecific.DAA_rekey));
  52.440 +       sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count, 
  52.441 +           sizeof(session->DAA_tpmSpecific.DAA_count));
  52.442 +-      sha1_update(&sha1, "\x01", 1);
  52.443 ++      sha1_update(&sha1, (BYTE *) "\x01", 1);
  52.444 +       sha1_final(&sha1, scratch + SHA1_DIGEST_LENGTH);
  52.445 +       mpz_init(f), mpz_init(q);
  52.446 +       mpz_import(f, 2 * SHA1_DIGEST_LENGTH, 1, 1, 0, 0, scratch);
  52.447 +@@ -787,14 +787,14 @@ info("tested until here");
  52.448 +           sizeof(session->DAA_tpmSpecific.DAA_rekey));
  52.449 +       sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count, 
  52.450 +           sizeof(session->DAA_tpmSpecific.DAA_count));
  52.451 +-      sha1_update(&sha1, "\x00", 1);
  52.452 ++      sha1_update(&sha1, (BYTE *) "\x00", 1);
  52.453 +       sha1_final(&sha1, scratch);
  52.454 +       sha1_init(&sha1);
  52.455 +       sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_rekey, 
  52.456 +           sizeof(session->DAA_tpmSpecific.DAA_rekey));
  52.457 +       sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count, 
  52.458 +           sizeof(session->DAA_tpmSpecific.DAA_count));
  52.459 +-      sha1_update(&sha1, "\x01", 1);
  52.460 ++      sha1_update(&sha1, (BYTE *) "\x01", 1);
  52.461 +       sha1_final(&sha1, scratch + SHA1_DIGEST_LENGTH);
  52.462 +       mpz_init(f), mpz_init(q);
  52.463 +       mpz_import(f, 2 * SHA1_DIGEST_LENGTH, 1, 1, 0, 0, scratch);
  52.464 +@@ -1440,14 +1440,14 @@ info("tested until here");
  52.465 +           sizeof(session->DAA_tpmSpecific.DAA_rekey));
  52.466 +       sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count, 
  52.467 +           sizeof(session->DAA_tpmSpecific.DAA_count));
  52.468 +-      sha1_update(&sha1, "\x00", 1);
  52.469 ++      sha1_update(&sha1, (BYTE *) "\x00", 1);
  52.470 +       sha1_final(&sha1, scratch);
  52.471 +       sha1_init(&sha1);
  52.472 +       sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_rekey, 
  52.473 +           sizeof(session->DAA_tpmSpecific.DAA_rekey));
  52.474 +       sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count, 
  52.475 +           sizeof(session->DAA_tpmSpecific.DAA_count));
  52.476 +-      sha1_update(&sha1, "\x01", 1);
  52.477 ++      sha1_update(&sha1, (BYTE *) "\x01", 1);
  52.478 +       sha1_final(&sha1, scratch + SHA1_DIGEST_LENGTH);
  52.479 +       mpz_init(f), mpz_init(q);
  52.480 +       mpz_import(f, 2 * SHA1_DIGEST_LENGTH, 1, 1, 0, 0, scratch);
  52.481 +@@ -1660,14 +1660,14 @@ info("tested until here");
  52.482 +           sizeof(session->DAA_tpmSpecific.DAA_rekey));
  52.483 +       sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count, 
  52.484 +           sizeof(session->DAA_tpmSpecific.DAA_count));
  52.485 +-      sha1_update(&sha1, "\x00", 1);
  52.486 ++      sha1_update(&sha1, (BYTE *) "\x00", 1);
  52.487 +       sha1_final(&sha1, scratch);
  52.488 +       sha1_init(&sha1);
  52.489 +       sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_rekey, 
  52.490 +           sizeof(session->DAA_tpmSpecific.DAA_rekey));
  52.491 +       sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count, 
  52.492 +           sizeof(session->DAA_tpmSpecific.DAA_count));
  52.493 +-      sha1_update(&sha1, "\x01", 1);
  52.494 ++      sha1_update(&sha1, (BYTE *) "\x01", 1);
  52.495 +       sha1_final(&sha1, scratch + SHA1_DIGEST_LENGTH);
  52.496 +       mpz_init(f), mpz_init(q);
  52.497 +       mpz_import(f, 2 * SHA1_DIGEST_LENGTH, 1, 1, 0, 0, scratch);
  52.498 +@@ -1740,14 +1740,14 @@ info("tested until here");
  52.499 +           sizeof(session->DAA_tpmSpecific.DAA_rekey));
  52.500 +       sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count, 
  52.501 +           sizeof(session->DAA_tpmSpecific.DAA_count));
  52.502 +-      sha1_update(&sha1, "\x00", 1);
  52.503 ++      sha1_update(&sha1, (BYTE *) "\x00", 1);
  52.504 +       sha1_final(&sha1, scratch);
  52.505 +       sha1_init(&sha1);
  52.506 +       sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_rekey, 
  52.507 +           sizeof(session->DAA_tpmSpecific.DAA_rekey));
  52.508 +       sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count, 
  52.509 +           sizeof(session->DAA_tpmSpecific.DAA_count));
  52.510 +-      sha1_update(&sha1, "\x01", 1);
  52.511 ++      sha1_update(&sha1, (BYTE *) "\x01", 1);
  52.512 +       sha1_final(&sha1, scratch + SHA1_DIGEST_LENGTH);
  52.513 +       mpz_init(f), mpz_init(q);
  52.514 +       mpz_import(f, 2 * SHA1_DIGEST_LENGTH, 1, 1, 0, 0, scratch);
  52.515 +@@ -2828,14 +2828,14 @@ TPM_RESULT TPM_DAA_Sign(TPM_HANDLE handl
  52.516 +           sizeof(session->DAA_tpmSpecific.DAA_rekey));
  52.517 +       sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count, 
  52.518 +           sizeof(session->DAA_tpmSpecific.DAA_count));
  52.519 +-      sha1_update(&sha1, "\x00", 1);
  52.520 ++      sha1_update(&sha1, (BYTE *) "\x00", 1);
  52.521 +       sha1_final(&sha1, scratch);
  52.522 +       sha1_init(&sha1);
  52.523 +       sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_rekey, 
  52.524 +           sizeof(session->DAA_tpmSpecific.DAA_rekey));
  52.525 +       sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count, 
  52.526 +           sizeof(session->DAA_tpmSpecific.DAA_count));
  52.527 +-      sha1_update(&sha1, "\x01", 1);
  52.528 ++      sha1_update(&sha1, (BYTE *) "\x01", 1);
  52.529 +       sha1_final(&sha1, scratch + SHA1_DIGEST_LENGTH);
  52.530 +       mpz_init(f), mpz_init(q);
  52.531 +       mpz_import(f, 2 * SHA1_DIGEST_LENGTH, 1, 1, 0, 0, scratch);
  52.532 +@@ -3050,7 +3050,7 @@ TPM_RESULT TPM_DAA_Sign(TPM_HANDLE handl
  52.533 +         sha1_init(&sha1);
  52.534 +         sha1_update(&sha1, (BYTE*) &session->DAA_session.DAA_digest, 
  52.535 +           sizeof(session->DAA_session.DAA_digest));
  52.536 +-        sha1_update(&sha1, "\x01", 1);
  52.537 ++        sha1_update(&sha1, (BYTE *) "\x01", 1);
  52.538 +         sha1_update(&sha1, inputData1, inputSize1);
  52.539 +         sha1_final(&sha1, (BYTE*) &session->DAA_session.DAA_digest);
  52.540 +       }
  52.541 +@@ -3078,7 +3078,7 @@ TPM_RESULT TPM_DAA_Sign(TPM_HANDLE handl
  52.542 +         sha1_init(&sha1);
  52.543 +         sha1_update(&sha1, (BYTE*) &session->DAA_session.DAA_digest, 
  52.544 +           sizeof(session->DAA_session.DAA_digest));
  52.545 +-        sha1_update(&sha1, "\x01", 1);
  52.546 ++        sha1_update(&sha1, (BYTE *) "\x01", 1);
  52.547 +         rsa_export_modulus(&aikData->key, scratch, &size);
  52.548 +         sha1_update(&sha1, scratch, size);
  52.549 +         sha1_final(&sha1, (BYTE*) &session->DAA_session.DAA_digest);
  52.550 +@@ -3134,14 +3134,14 @@ TPM_RESULT TPM_DAA_Sign(TPM_HANDLE handl
  52.551 +           sizeof(session->DAA_tpmSpecific.DAA_rekey));
  52.552 +       sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count, 
  52.553 +           sizeof(session->DAA_tpmSpecific.DAA_count));
  52.554 +-      sha1_update(&sha1, "\x00", 1);
  52.555 ++      sha1_update(&sha1, (BYTE *) "\x00", 1);
  52.556 +       sha1_final(&sha1, scratch);
  52.557 +       sha1_init(&sha1);
  52.558 +       sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_rekey, 
  52.559 +           sizeof(session->DAA_tpmSpecific.DAA_rekey));
  52.560 +       sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count, 
  52.561 +           sizeof(session->DAA_tpmSpecific.DAA_count));
  52.562 +-      sha1_update(&sha1, "\x01", 1);
  52.563 ++      sha1_update(&sha1, (BYTE *) "\x01", 1);
  52.564 +       sha1_final(&sha1, scratch + SHA1_DIGEST_LENGTH);
  52.565 +       mpz_init(f), mpz_init(q);
  52.566 +       mpz_import(f, 2 * SHA1_DIGEST_LENGTH, 1, 1, 0, 0, scratch);
  52.567 +@@ -3213,14 +3213,14 @@ TPM_RESULT TPM_DAA_Sign(TPM_HANDLE handl
  52.568 +           sizeof(session->DAA_tpmSpecific.DAA_rekey));
  52.569 +       sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count, 
  52.570 +           sizeof(session->DAA_tpmSpecific.DAA_count));
  52.571 +-      sha1_update(&sha1, "\x00", 1);
  52.572 ++      sha1_update(&sha1, (BYTE *) "\x00", 1);
  52.573 +       sha1_final(&sha1, scratch);
  52.574 +       sha1_init(&sha1);
  52.575 +       sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_rekey, 
  52.576 +           sizeof(session->DAA_tpmSpecific.DAA_rekey));
  52.577 +       sha1_update(&sha1, (BYTE*) &session->DAA_tpmSpecific.DAA_count, 
  52.578 +           sizeof(session->DAA_tpmSpecific.DAA_count));
  52.579 +-      sha1_update(&sha1, "\x01", 1);
  52.580 ++      sha1_update(&sha1, (BYTE *) "\x01", 1);
  52.581 +       sha1_final(&sha1, scratch + SHA1_DIGEST_LENGTH);
  52.582 +       mpz_init(f), mpz_init(q);
  52.583 +       mpz_import(f, 2 * SHA1_DIGEST_LENGTH, 1, 1, 0, 0, scratch);
  52.584 +diff -uprN orig/tpm_emulator-0.3-x86_64/tpm/tpm_data.c vtpm/tpm/tpm_data.c
  52.585 +--- orig/tpm_emulator-0.3-x86_64/tpm/tpm_data.c	2006-05-30 12:28:02.000000000 -0700
  52.586 ++++ vtpm/tpm/tpm_data.c	2006-05-30 12:23:26.000000000 -0700
  52.587  @@ -1,6 +1,7 @@
  52.588   /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
  52.589    * Copyright (C) 2004 Mario Strasser <mast@gmx.net>,
  52.590 @@ -698,8 +876,8 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
  52.591    *
  52.592    * This module is free software; you can redistribute it and/or modify
  52.593    * it under the terms of the GNU General Public License as published
  52.594 -@@ -15,9 +16,15 @@
  52.595 -  * $Id: tpm_data.c 9 2005-04-26 18:15:31Z mast $
  52.596 +@@ -15,10 +16,15 @@
  52.597 +  * $Id: tpm_data.c 36 2005-10-26 20:31:19Z hstamer $
  52.598    */
  52.599   
  52.600  +#include <sys/types.h>
  52.601 @@ -710,11 +888,12 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
  52.602   #include "tpm_emulator.h"
  52.603   #include "tpm_structures.h"
  52.604   #include "tpm_marshalling.h"
  52.605 +-#include "linux_module.h"
  52.606  +#include "vtpm_manager.h"
  52.607   
  52.608   TPM_DATA tpmData;
  52.609   
  52.610 -@@ -28,6 +35,7 @@ BOOL tpm_get_physical_presence(void)
  52.611 +@@ -39,6 +45,7 @@ static inline void init_pcr_attr(int pcr
  52.612   
  52.613   void tpm_init_data(void)
  52.614   {
  52.615 @@ -722,7 +901,7 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
  52.616     /* endorsement key */
  52.617     uint8_t ek_n[] =  "\xa8\xdb\xa9\x42\xa8\xf3\xb8\x06\x85\x90\x76\x93\xad\xf7"
  52.618       "\x74\xec\x3f\xd3\x3d\x9d\xe8\x2e\xff\x15\xed\x0e\xce\x5f\x93"
  52.619 -@@ -66,6 +74,8 @@ void tpm_init_data(void)
  52.620 +@@ -77,6 +84,8 @@ void tpm_init_data(void)
  52.621       "\xd1\xc0\x8b\x5b\xa2\x2e\xa7\x15\xca\x50\x75\x10\x48\x9c\x2b"
  52.622       "\x18\xb9\x67\x8f\x5d\x64\xc3\x28\x9f\x2f\x16\x2f\x08\xda\x47"
  52.623       "\xec\x86\x43\x0c\x80\x99\x07\x34\x0f";
  52.624 @@ -731,18 +910,7 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
  52.625     int i;
  52.626     /* reset all data to NULL, FALSE or 0 */
  52.627     memset(&tpmData, 0, sizeof(tpmData));
  52.628 -@@ -85,6 +95,10 @@ void tpm_init_data(void)
  52.629 -   tpmData.permanent.data.version.revMinor = VERSION_MINOR;
  52.630 -   /* setup PCR attributes */
  52.631 -   for (i = 0; i < TPM_NUM_PCR; i++) {
  52.632 -+    int j;
  52.633 -+    for (j=0; j < TPM_NUM_LOCALITY; j++) {
  52.634 -+      tpmData.permanent.data.pcrAttrib[i].pcrExtendLocal[j] = TRUE;
  52.635 -+    }
  52.636 -     tpmData.permanent.data.pcrAttrib[i].pcrReset = TRUE;
  52.637 -   }
  52.638 -   /* set tick type */
  52.639 -@@ -115,49 +129,235 @@ void tpm_release_data(void)
  52.640 +@@ -150,49 +159,235 @@ void tpm_release_data(void)
  52.641   
  52.642   #ifdef TPM_STORE_TO_FILE
  52.643   
  52.644 @@ -1009,7 +1177,7 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
  52.645   }
  52.646   
  52.647   #else
  52.648 -@@ -232,7 +432,6 @@ int tpm_restore_permanent_data(void)
  52.649 +@@ -267,7 +462,6 @@ int tpm_restore_permanent_data(void)
  52.650   
  52.651   int tpm_erase_permanent_data(void)
  52.652   {
  52.653 @@ -1018,9 +1186,9 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
  52.654     return res;
  52.655   }
  52.656  -
  52.657 -diff -uprN orig/tpm_emulator-0.2-x86_64/tpm/tpm_deprecated.c vtpm/tpm/tpm_deprecated.c
  52.658 ---- orig/tpm_emulator-0.2-x86_64/tpm/tpm_deprecated.c	2005-08-15 00:58:57.000000000 -0700
  52.659 -+++ vtpm/tpm/tpm_deprecated.c	2006-05-17 09:31:11.000000000 -0700
  52.660 +diff -uprN orig/tpm_emulator-0.3-x86_64/tpm/tpm_deprecated.c vtpm/tpm/tpm_deprecated.c
  52.661 +--- orig/tpm_emulator-0.3-x86_64/tpm/tpm_deprecated.c	2006-01-10 04:21:45.000000000 -0800
  52.662 ++++ vtpm/tpm/tpm_deprecated.c	2006-05-30 12:23:26.000000000 -0700
  52.663  @@ -1,6 +1,7 @@
  52.664   /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
  52.665    * Copyright (C) 2004 Mario Strasser <mast@gmx.net>,
  52.666 @@ -1047,9 +1215,9 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
  52.667                           authContextSize, &contextBlob);
  52.668     if (res != TPM_SUCCESS) return res;
  52.669     len = *authContextSize;
  52.670 -diff -uprN orig/tpm_emulator-0.2-x86_64/tpm/tpm_emulator.h vtpm/tpm/tpm_emulator.h
  52.671 ---- orig/tpm_emulator-0.2-x86_64/tpm/tpm_emulator.h	2005-08-15 00:58:57.000000000 -0700
  52.672 -+++ vtpm/tpm/tpm_emulator.h	2006-05-17 09:31:11.000000000 -0700
  52.673 +diff -uprN orig/tpm_emulator-0.3-x86_64/tpm/tpm_emulator.h vtpm/tpm/tpm_emulator.h
  52.674 +--- orig/tpm_emulator-0.3-x86_64/tpm/tpm_emulator.h	2006-01-10 04:21:45.000000000 -0800
  52.675 ++++ vtpm/tpm/tpm_emulator.h	2006-05-30 12:23:26.000000000 -0700
  52.676  @@ -1,5 +1,6 @@
  52.677   /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
  52.678    * Copyright (C) 2004 Mario Strasser <mast@gmx.net>,
  52.679 @@ -1064,12 +1232,12 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
  52.680  -#undef  TPM_GENERATE_EK
  52.681  +//#undef  TPM_GENERATE_EK
  52.682  +#define  TPM_GENERATE_EK
  52.683 + #undef  TPM_GENERATE_SEED_DAA
  52.684   
  52.685 - /**
  52.686 -  * tpm_emulator_init - initialises and starts the TPM emulator
  52.687 -diff -uprN orig/tpm_emulator-0.2-x86_64/tpm/tpm_integrity.c vtpm/tpm/tpm_integrity.c
  52.688 ---- orig/tpm_emulator-0.2-x86_64/tpm/tpm_integrity.c	2005-08-15 00:58:57.000000000 -0700
  52.689 -+++ vtpm/tpm/tpm_integrity.c	2006-05-17 09:31:11.000000000 -0700
  52.690 + #define TPM_MANUFACTURER 0x4554485A /* 'ETHZ' */        
  52.691 +diff -uprN orig/tpm_emulator-0.3-x86_64/tpm/tpm_integrity.c vtpm/tpm/tpm_integrity.c
  52.692 +--- orig/tpm_emulator-0.3-x86_64/tpm/tpm_integrity.c	2006-01-10 04:21:45.000000000 -0800
  52.693 ++++ vtpm/tpm/tpm_integrity.c	2006-05-30 12:23:26.000000000 -0700
  52.694  @@ -1,6 +1,7 @@
  52.695   /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
  52.696    * Copyright (C) 2004 Mario Strasser <mast@gmx.net>,
  52.697 @@ -1083,9 +1251,9 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
  52.698     return TPM_SUCCESS;
  52.699   }
  52.700  -
  52.701 -diff -uprN orig/tpm_emulator-0.2-x86_64/tpm/tpm_structures.h vtpm/tpm/tpm_structures.h
  52.702 ---- orig/tpm_emulator-0.2-x86_64/tpm/tpm_structures.h	2005-08-15 00:58:57.000000000 -0700
  52.703 -+++ vtpm/tpm/tpm_structures.h	2006-05-17 09:31:11.000000000 -0700
  52.704 +diff -uprN orig/tpm_emulator-0.3-x86_64/tpm/tpm_structures.h vtpm/tpm/tpm_structures.h
  52.705 +--- orig/tpm_emulator-0.3-x86_64/tpm/tpm_structures.h	2006-01-10 04:21:45.000000000 -0800
  52.706 ++++ vtpm/tpm/tpm_structures.h	2006-05-30 12:23:26.000000000 -0700
  52.707  @@ -1,6 +1,7 @@
  52.708   /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
  52.709    * Copyright (C) 2004 Mario Strasser <mast@gmx.net>,
  52.710 @@ -1103,9 +1271,9 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
  52.711   #include "crypto/rsa.h"
  52.712   
  52.713   /*
  52.714 -diff -uprN orig/tpm_emulator-0.2-x86_64/tpm/tpm_testing.c vtpm/tpm/tpm_testing.c
  52.715 ---- orig/tpm_emulator-0.2-x86_64/tpm/tpm_testing.c	2005-08-15 00:58:57.000000000 -0700
  52.716 -+++ vtpm/tpm/tpm_testing.c	2006-05-17 09:31:11.000000000 -0700
  52.717 +diff -uprN orig/tpm_emulator-0.3-x86_64/tpm/tpm_testing.c vtpm/tpm/tpm_testing.c
  52.718 +--- orig/tpm_emulator-0.3-x86_64/tpm/tpm_testing.c	2006-01-10 04:21:45.000000000 -0800
  52.719 ++++ vtpm/tpm/tpm_testing.c	2006-05-30 12:23:26.000000000 -0700
  52.720  @@ -1,6 +1,7 @@
  52.721   /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
  52.722    * Copyright (C) 2004 Mario Strasser <mast@gmx.net>,
  52.723 @@ -1221,9 +1389,9 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
  52.724     rsa_private_key_t priv_key;
  52.725     rsa_public_key_t pub_key;
  52.726   
  52.727 -diff -uprN orig/tpm_emulator-0.2-x86_64/tpm/tpm_ticks.c vtpm/tpm/tpm_ticks.c
  52.728 ---- orig/tpm_emulator-0.2-x86_64/tpm/tpm_ticks.c	2005-08-15 00:58:57.000000000 -0700
  52.729 -+++ vtpm/tpm/tpm_ticks.c	2006-05-17 09:31:11.000000000 -0700
  52.730 +diff -uprN orig/tpm_emulator-0.3-x86_64/tpm/tpm_ticks.c vtpm/tpm/tpm_ticks.c
  52.731 +--- orig/tpm_emulator-0.3-x86_64/tpm/tpm_ticks.c	2006-01-10 04:21:45.000000000 -0800
  52.732 ++++ vtpm/tpm/tpm_ticks.c	2006-05-30 12:23:26.000000000 -0700
  52.733  @@ -1,6 +1,7 @@
  52.734   /* Software-Based Trusted Platform Module (TPM) Emulator for Linux
  52.735    * Copyright (C) 2004 Mario Strasser <mast@gmx.net>,
  52.736 @@ -1306,9 +1474,69 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/
  52.737   }
  52.738     
  52.739   
  52.740 -diff -uprN orig/tpm_emulator-0.2-x86_64/tpmd.c vtpm/tpmd.c
  52.741 ---- orig/tpm_emulator-0.2-x86_64/tpmd.c	1969-12-31 16:00:00.000000000 -0800
  52.742 -+++ vtpm/tpmd.c	2006-05-17 09:31:11.000000000 -0700
  52.743 +diff -uprN orig/tpm_emulator-0.3-x86_64/tpm/tpm_transport.c vtpm/tpm/tpm_transport.c
  52.744 +--- orig/tpm_emulator-0.3-x86_64/tpm/tpm_transport.c	2006-01-10 04:21:45.000000000 -0800
  52.745 ++++ vtpm/tpm/tpm_transport.c	2006-05-30 12:23:26.000000000 -0700
  52.746 +@@ -59,7 +59,7 @@ static int decrypt_transport_auth(TPM_KE
  52.747 + static void transport_log_in(TPM_COMMAND_CODE ordinal, BYTE parameters[20],
  52.748 +                              BYTE pubKeyHash[20], TPM_DIGEST *transDigest)
  52.749 + {
  52.750 +-  UINT32 tag = cpu_to_be32(TPM_TAG_TRANSPORT_LOG_IN);
  52.751 ++  UINT32 tag = CPU_TO_BE32(TPM_TAG_TRANSPORT_LOG_IN);
  52.752 +   BYTE *ptr, buf[sizeof_TPM_TRANSPORT_LOG_IN(x)];
  52.753 +   UINT32 len = sizeof(buf);
  52.754 +   sha1_ctx_t sha1;
  52.755 +@@ -76,7 +76,7 @@ static void transport_log_in(TPM_COMMAND
  52.756 + static void transport_log_out(TPM_CURRENT_TICKS *currentTicks, BYTE parameters[20],
  52.757 +                               TPM_MODIFIER_INDICATOR locality, TPM_DIGEST *transDigest)
  52.758 + {
  52.759 +-  UINT32 tag = cpu_to_be32(TPM_TAG_TRANSPORT_LOG_OUT);
  52.760 ++  UINT32 tag = CPU_TO_BE32(TPM_TAG_TRANSPORT_LOG_OUT);
  52.761 +   BYTE *ptr, buf[sizeof_TPM_TRANSPORT_LOG_OUT(x)];
  52.762 +   UINT32 len = sizeof(buf);
  52.763 +   sha1_ctx_t sha1;
  52.764 +@@ -191,7 +191,7 @@ static void decrypt_wrapped_command(BYTE
  52.765 +     sha1_update(&sha1, auth->nonceOdd.nonce, sizeof(auth->nonceOdd.nonce));
  52.766 +     sha1_update(&sha1, "in", 2);
  52.767 +     sha1_update(&sha1, secret, sizeof(TPM_SECRET));
  52.768 +-    j = cpu_to_be32(i);
  52.769 ++    j = CPU_TO_BE32(i);
  52.770 +     sha1_update(&sha1, (BYTE*)&j, 4);
  52.771 +     sha1_final(&sha1, mask);
  52.772 +     for (j = 0; j < sizeof(mask) && buf_len > 0; j++) { 
  52.773 +@@ -213,7 +213,7 @@ static void encrypt_wrapped_command(BYTE
  52.774 +     sha1_update(&sha1, auth->nonceOdd.nonce, sizeof(auth->nonceOdd.nonce));
  52.775 +     sha1_update(&sha1, "out", 3);
  52.776 +     sha1_update(&sha1, secret, sizeof(TPM_SECRET));
  52.777 +-    j = cpu_to_be32(i);
  52.778 ++    j = CPU_TO_BE32(i);
  52.779 +     sha1_update(&sha1, (BYTE*)&j, 4);
  52.780 +     sha1_final(&sha1, mask);
  52.781 +     for (j = 0; j < sizeof(mask) && buf_len > 0; j++) { 
  52.782 +@@ -253,9 +253,9 @@ TPM_RESULT TPM_ExecuteTransport(UINT32 i
  52.783 +   /* verify authorization */
  52.784 +   tpm_compute_in_param_digest(&req);
  52.785 +   sha1_init(&sha1);
  52.786 +-  res = cpu_to_be32(TPM_ORD_ExecuteTransport);
  52.787 ++  res = CPU_TO_BE32(TPM_ORD_ExecuteTransport);
  52.788 +   sha1_update(&sha1, (BYTE*)&res, 4);
  52.789 +-  res = cpu_to_be32(inWrappedCmdSize);
  52.790 ++  res = CPU_TO_BE32(inWrappedCmdSize);
  52.791 +   sha1_update(&sha1, (BYTE*)&res, 4);
  52.792 +   sha1_update(&sha1, req.auth1.digest, sizeof(req.auth1.digest));
  52.793 +   sha1_final(&sha1, auth1->digest);
  52.794 +@@ -357,7 +357,7 @@ TPM_RESULT TPM_ReleaseTransportSigned(TP
  52.795 +   /* setup a TPM_SIGN_INFO structure */
  52.796 +   memcpy(&buf[0], "\x05\x00TRAN", 6);
  52.797 +   memcpy(&buf[6], antiReplay->nonce, 20);
  52.798 +-  *(UINT32*)&buf[26] = cpu_to_be32(20);
  52.799 ++  *(UINT32*)&buf[26] = CPU_TO_BE32(20);
  52.800 +   memcpy(&buf[30], session->transInternal.transDigest.digest, 20);
  52.801 +   /* sign info structure */ 
  52.802 +   res = tpm_sign(key, auth1, TRUE, buf, sizeof(buf), signature, signSize);
  52.803 +diff -uprN orig/tpm_emulator-0.3-x86_64/tpmd.c vtpm/tpmd.c
  52.804 +--- orig/tpm_emulator-0.3-x86_64/tpmd.c	1969-12-31 16:00:00.000000000 -0800
  52.805 ++++ vtpm/tpmd.c	2006-05-30 12:23:26.000000000 -0700
  52.806  @@ -0,0 +1,207 @@
  52.807  +/* Software-Based Trusted Platform Module (TPM) Emulator for Linux
  52.808  + * Copyright (C) 2005 INTEL Corp
    53.1 --- a/xen/arch/x86/domain.c	Wed May 31 11:30:07 2006 -0600
    53.2 +++ b/xen/arch/x86/domain.c	Wed May 31 13:05:21 2006 -0600
    53.3 @@ -146,6 +146,8 @@ struct vcpu *alloc_vcpu_struct(struct do
    53.4      v->arch.guest_vl4table = __linear_l4_table;
    53.5  #endif
    53.6  
    53.7 +    pae_l3_cache_init(&v->arch.pae_l3_cache);
    53.8 +
    53.9      return v;
   53.10  }
   53.11  
    54.1 --- a/xen/arch/x86/hvm/io.c	Wed May 31 11:30:07 2006 -0600
    54.2 +++ b/xen/arch/x86/hvm/io.c	Wed May 31 13:05:21 2006 -0600
    54.3 @@ -648,6 +648,16 @@ static void hvm_mmio_assist(struct vcpu 
    54.4              regs->eflags &= ~X86_EFLAGS_CF;
    54.5  
    54.6          break;
    54.7 +
    54.8 +    case INSTR_XCHG:
    54.9 +	if (src & REGISTER) {
   54.10 +		index = operand_index(src);
   54.11 +		set_reg_value(size, index, 0, regs, p->u.data);
   54.12 +	} else {
   54.13 +		index = operand_index(dst);
   54.14 +		set_reg_value(size, index, 0, regs, p->u.data);
   54.15 +	}
   54.16 +	break;
   54.17      }
   54.18  
   54.19      hvm_load_cpu_guest_regs(v, regs);
    55.1 --- a/xen/arch/x86/hvm/platform.c	Wed May 31 11:30:07 2006 -0600
    55.2 +++ b/xen/arch/x86/hvm/platform.c	Wed May 31 13:05:21 2006 -0600
    55.3 @@ -954,10 +954,26 @@ void handle_mmio(unsigned long va, unsig
    55.4          mmio_opp->instr = mmio_inst.instr;
    55.5          mmio_opp->operand[0] = mmio_inst.operand[0]; /* source */
    55.6          mmio_opp->operand[1] = mmio_inst.operand[1]; /* destination */
    55.7 -
    55.8 -        /* send the request and wait for the value */
    55.9 -        send_mmio_req(IOREQ_TYPE_XCHG, gpa, 1,
   55.10 -                      mmio_inst.op_size, 0, IOREQ_WRITE, 0);
   55.11 +	if (mmio_inst.operand[0] & REGISTER) {
   55.12 +		long value;
   55.13 +		unsigned long operand = mmio_inst.operand[0];
   55.14 +		value = get_reg_value(operand_size(operand), 
   55.15 +				      operand_index(operand), 0,
   55.16 +                    		      mmio_opp->inst_decoder_regs);
   55.17 +        	/* send the request and wait for the value */
   55.18 +        	send_mmio_req(IOREQ_TYPE_XCHG, gpa, 1,
   55.19 +                      mmio_inst.op_size, value, IOREQ_WRITE, 0);
   55.20 +	} else {
   55.21 +		/* the destination is a register */
   55.22 +		long value;
   55.23 +		unsigned long operand = mmio_inst.operand[1];
   55.24 +		value = get_reg_value(operand_size(operand), 
   55.25 +				      operand_index(operand), 0,
   55.26 +                    		      mmio_opp->inst_decoder_regs);
   55.27 +        	/* send the request and wait for the value */
   55.28 +        	send_mmio_req(IOREQ_TYPE_XCHG, gpa, 1,
   55.29 +                      mmio_inst.op_size, value, IOREQ_WRITE, 0);
   55.30 +	}
   55.31          break;
   55.32  
   55.33      default:
    56.1 --- a/xen/arch/x86/hvm/svm/svm.c	Wed May 31 11:30:07 2006 -0600
    56.2 +++ b/xen/arch/x86/hvm/svm/svm.c	Wed May 31 13:05:21 2006 -0600
    56.3 @@ -51,9 +51,6 @@
    56.4  
    56.5  #define SVM_EXTRA_DEBUG
    56.6  
    56.7 -/* Useful define */
    56.8 -#define MAX_INST_SIZE  15
    56.9 -
   56.10  #define set_segment_register(name, value)  \
   56.11         __asm__ __volatile__ ( "movw %%ax ,%%" STR(name) "" : : "a" (value) )
   56.12  
   56.13 @@ -74,6 +71,9 @@ void svm_manual_event_injection32(struct
   56.14  void svm_dump_regs(const char *from, struct cpu_user_regs *regs);
   56.15  
   56.16  static void svm_relinquish_guest_resources(struct domain *d);
   56.17 +static int svm_do_vmmcall_reset_to_realmode(struct vcpu *v,
   56.18 +        struct cpu_user_regs *regs);
   56.19 +
   56.20  
   56.21  
   56.22  extern void set_hsa_to_guest( struct arch_svm_struct *arch_svm );
   56.23 @@ -438,6 +438,42 @@ unsigned long svm_get_ctrl_reg(struct vc
   56.24      return 0;                   /* dummy */
   56.25  }
   56.26  
   56.27 +
   56.28 +/* SVM-specific intitialization code for VCPU application processors */
   56.29 +void svm_init_ap_context(struct vcpu_guest_context *ctxt, 
   56.30 +        int vcpuid, int trampoline_vector)
   56.31 +{
   56.32 +    int i;
   56.33 +    struct vcpu *v, *bsp = current;
   56.34 +    struct domain *d = bsp->domain;
   56.35 +    cpu_user_regs_t *regs;;
   56.36 +
   56.37 +  
   56.38 +    if ((v = d->vcpu[vcpuid]) == NULL)
   56.39 +    {
   56.40 +        printk("vcpuid %d is invalid!  good-bye.\n", vcpuid);
   56.41 +        domain_crash_synchronous();
   56.42 +    }
   56.43 +    regs = &v->arch.guest_context.user_regs;
   56.44 +
   56.45 +    memset(ctxt, 0, sizeof(*ctxt));
   56.46 +    for (i = 0; i < 256; ++i)
   56.47 +    {
   56.48 +        ctxt->trap_ctxt[i].vector = i;
   56.49 +        ctxt->trap_ctxt[i].cs = FLAT_KERNEL_CS;
   56.50 +    }
   56.51 +
   56.52 +
   56.53 +    /*
   56.54 +     * We execute the trampoline code in real mode. The trampoline vector
   56.55 +     * passed to us is page alligned and is the physicall frame number for
   56.56 +     * the code. We will execute this code in real mode. 
   56.57 +     */
   56.58 +    ctxt->user_regs.eip = 0x0;
   56.59 +    ctxt->user_regs.cs = (trampoline_vector << 8); 
   56.60 +    ctxt->flags = VGCF_HVM_GUEST;
   56.61 +}
   56.62 +
   56.63  int start_svm(void)
   56.64  {
   56.65      u32 eax, ecx, edx;
   56.66 @@ -484,6 +520,7 @@ int start_svm(void)
   56.67      hvm_funcs.paging_enabled = svm_paging_enabled;
   56.68      hvm_funcs.instruction_length = svm_instruction_length;
   56.69      hvm_funcs.get_guest_ctrl_reg = svm_get_ctrl_reg;
   56.70 +    hvm_funcs.init_ap_context = svm_init_ap_context;
   56.71  
   56.72      hvm_enabled = 1;    
   56.73  
   56.74 @@ -660,6 +697,20 @@ static void arch_svm_do_launch(struct vc
   56.75      if (svm_dbg_on)
   56.76          svm_dump_host_regs(__func__);
   56.77  #endif
   56.78 +    if (v->vcpu_id != 0) 
   56.79 +    {
   56.80 +    	u16	cs_sel = regs->cs;
   56.81 +    	/*
   56.82 +	 * This is the launch of an AP; set state so that we begin executing
   56.83 +    	 * the trampoline code in real-mode.
   56.84 +	 */
   56.85 +    	svm_do_vmmcall_reset_to_realmode(v, regs); 	
   56.86 +    	/* Adjust the state to execute the trampoline code.*/
   56.87 +    	v->arch.hvm_svm.vmcb->rip = 0;
   56.88 +    	v->arch.hvm_svm.vmcb->cs.sel= cs_sel;
   56.89 +    	v->arch.hvm_svm.vmcb->cs.base = (cs_sel << 4);
   56.90 +    }
   56.91 +     	
   56.92      reset_stack_and_jump(svm_asm_do_launch);
   56.93  }
   56.94  
   56.95 @@ -896,8 +947,10 @@ static void svm_do_general_protection_fa
   56.96      svm_inject_exception(v, TRAP_gp_fault, 1, error_code);
   56.97  }
   56.98  
   56.99 -/* Reserved bits: [31:14], [12:1] */
  56.100 -#define SVM_VCPU_CPUID_L1_RESERVED 0xffffdffe
  56.101 +/* Reserved bits ECX: [31:14], [12:4], [2:1]*/
  56.102 +#define SVM_VCPU_CPUID_L1_ECX_RESERVED 0xffffdff6
  56.103 +/* Reserved bits EDX: [31:29], [27], [22:20], [18], [10] */
  56.104 +#define SVM_VCPU_CPUID_L1_EDX_RESERVED 0xe8740400
  56.105  
  56.106  static void svm_vmexit_do_cpuid(struct vmcb_struct *vmcb, unsigned long input, 
  56.107          struct cpu_user_regs *regs) 
  56.108 @@ -920,20 +973,17 @@ static void svm_vmexit_do_cpuid(struct v
  56.109  
  56.110      cpuid(input, &eax, &ebx, &ecx, &edx);
  56.111  
  56.112 -    if (input == 1)
  56.113 +    if (input == 0x00000001)
  56.114      {
  56.115          if ( !hvm_apic_support(v->domain) ||
  56.116                  !vlapic_global_enabled((VLAPIC(v))) )
  56.117          {
  56.118 -            clear_bit(X86_FEATURE_APIC, &edx);
  56.119 -            /* Since the apic is disabled, avoid any confusion about SMP cpus being available */
  56.120 -            clear_bit(X86_FEATURE_HT, &edx);  /* clear the hyperthread bit */
  56.121 -            ebx &= 0xFF00FFFF;  /* set the logical processor count to 1 */
  56.122 -            ebx |= 0x00010000;
  56.123 +            /* Since the apic is disabled, avoid any confusion 
  56.124 +	       about SMP cpus being available */
  56.125 +	    clear_bit(X86_FEATURE_APIC, &edx);
  56.126          }
  56.127 -	    
  56.128 +
  56.129  #if CONFIG_PAGING_LEVELS < 3
  56.130 -        clear_bit(X86_FEATURE_NX, &edx);
  56.131          clear_bit(X86_FEATURE_PAE, &edx);
  56.132          clear_bit(X86_FEATURE_PSE, &edx);
  56.133          clear_bit(X86_FEATURE_PSE36, &edx);
  56.134 @@ -942,24 +992,90 @@ static void svm_vmexit_do_cpuid(struct v
  56.135          {
  56.136              if ( !v->domain->arch.hvm_domain.pae_enabled )
  56.137              {
  56.138 -               clear_bit(X86_FEATURE_PAE, &edx);
  56.139 -               clear_bit(X86_FEATURE_NX, &edx);
  56.140 +		clear_bit(X86_FEATURE_PAE, &edx);
  56.141              }
  56.142              clear_bit(X86_FEATURE_PSE, &edx);
  56.143              clear_bit(X86_FEATURE_PSE36, &edx);
  56.144          }
  56.145  #endif	
  56.146          /* Clear out reserved bits. */
  56.147 -        ecx &= ~SVM_VCPU_CPUID_L1_RESERVED; /* mask off reserved bits */
  56.148 +        ecx &= ~SVM_VCPU_CPUID_L1_ECX_RESERVED;
  56.149 +        edx &= ~SVM_VCPU_CPUID_L1_EDX_RESERVED;
  56.150 +
  56.151          clear_bit(X86_FEATURE_MWAIT & 31, &ecx);
  56.152 +
  56.153 +	/* Guest should only see one logical processor.
  56.154 +	 * See details on page 23 of AMD CPUID Specification. 
  56.155 +	*/
  56.156 +	clear_bit(X86_FEATURE_HT, &edx);  /* clear the hyperthread bit */
  56.157 +	ebx &= 0xFF00FFFF;  /* clear the logical processor count when HTT=0 */
  56.158 +	ebx |= 0x00010000;  /* set to 1 just for precaution */
  56.159      }
  56.160 -#ifdef __i386__
  56.161 +    else if ( ( input > 0x00000005 ) && ( input < 0x80000000 ) )
  56.162 +    {
  56.163 +	eax = ebx = ecx = edx = 0x0;
  56.164 +    }
  56.165      else if ( input == 0x80000001 )
  56.166      {
  56.167 +	/* We duplicate some CPUID_00000001 code because many bits of 
  56.168 +	   CPUID_80000001_EDX overlaps with CPUID_00000001_EDX. */
  56.169 +
  56.170 +        if ( !hvm_apic_support(v->domain) ||
  56.171 +	     !vlapic_global_enabled((VLAPIC(v))) )
  56.172 +        {
  56.173 +            /* Since the apic is disabled, avoid any confusion 
  56.174 +	       about SMP cpus being available */
  56.175 +	    clear_bit(X86_FEATURE_APIC, &edx);
  56.176 +        }
  56.177 +
  56.178 +	/* Clear the Cmp_Legacy bit 
  56.179 +	 * This bit is supposed to be zero when HTT = 0.
  56.180 +	 * See details on page 23 of AMD CPUID Specification. 
  56.181 +	*/
  56.182 +	clear_bit(X86_FEATURE_CMP_LEGACY & 31, &ecx);
  56.183 +
  56.184 +#ifdef __i386__
  56.185          /* Mask feature for Intel ia32e or AMD long mode. */
  56.186 +        clear_bit(X86_FEATURE_LAHF_LM & 31, &ecx);
  56.187 +
  56.188          clear_bit(X86_FEATURE_LM & 31, &edx);
  56.189 +        clear_bit(X86_FEATURE_SYSCALL & 31, &edx);
  56.190 +#endif
  56.191 +
  56.192 +#if CONFIG_PAGING_LEVELS < 3
  56.193 +	clear_bit(X86_FEATURE_NX & 31, &edx);
  56.194 +        clear_bit(X86_FEATURE_PAE, &edx);
  56.195 +        clear_bit(X86_FEATURE_PSE, &edx);
  56.196 +        clear_bit(X86_FEATURE_PSE36, &edx);
  56.197 +#else
  56.198 +        if ( v->domain->arch.ops->guest_paging_levels == PAGING_L2 )
  56.199 +        {
  56.200 +            if ( !v->domain->arch.hvm_domain.pae_enabled )
  56.201 +            {
  56.202 +		clear_bit(X86_FEATURE_NX & 31, &edx);
  56.203 +		clear_bit(X86_FEATURE_PAE, &edx);
  56.204 +            }
  56.205 +            clear_bit(X86_FEATURE_PSE, &edx);
  56.206 +            clear_bit(X86_FEATURE_PSE36, &edx);
  56.207 +        }
  56.208 +#endif	
  56.209 +
  56.210 +        /* Make SVM feature invisible to the guest. */
  56.211 +        clear_bit(X86_FEATURE_SVME & 31, &ecx);
  56.212 +	
  56.213 +	/* So far, we do not support 3DNow for the guest. */
  56.214 +	clear_bit(X86_FEATURE_3DNOW & 31, &edx);
  56.215 +	clear_bit(X86_FEATURE_3DNOWEXT & 31, &edx);
  56.216      }
  56.217 -#endif
  56.218 +    else if ( ( input == 0x80000007 ) || ( input == 0x8000000A  ) )
  56.219 +    {
  56.220 +	/* Mask out features of power management and SVM extension. */
  56.221 +	eax = ebx = ecx = edx = 0;
  56.222 +    }
  56.223 +    else if ( input == 0x80000008 )
  56.224 +    {
  56.225 +	ecx &= 0xFFFFFF00; /* Make sure Number of CPU core is 1 when HTT=0 */
  56.226 +    }
  56.227  
  56.228      regs->eax = (unsigned long)eax;
  56.229      regs->ebx = (unsigned long)ebx;
  56.230 @@ -2036,7 +2152,7 @@ static void svm_debug_restore_cpu_user_r
  56.231  void svm_handle_invlpg(const short invlpga, struct cpu_user_regs *regs)
  56.232  {
  56.233      struct vcpu *v = current;
  56.234 -    u8 opcode[MAX_INST_SIZE], prefix, length = MAX_INST_SIZE;
  56.235 +    u8 opcode[MAX_INST_LEN], prefix, length = MAX_INST_LEN;
  56.236      unsigned long g_vaddr;
  56.237      int inst_len;
  56.238      struct vmcb_struct *vmcb = v->arch.hvm_svm.vmcb;
    57.1 --- a/xen/arch/x86/mm.c	Wed May 31 11:30:07 2006 -0600
    57.2 +++ b/xen/arch/x86/mm.c	Wed May 31 13:05:21 2006 -0600
    57.3 @@ -260,39 +260,86 @@ void share_xen_page_with_privileged_gues
    57.4      share_xen_page_with_guest(page, dom_xen, readonly);
    57.5  }
    57.6  
    57.7 +#if defined(CONFIG_X86_PAE)
    57.8 +
    57.9 +#ifdef NDEBUG
   57.10 +/* Only PDPTs above 4GB boundary need to be shadowed in low memory. */
   57.11 +#define l3tab_needs_shadow(mfn) (mfn >= 0x100000)
   57.12 +#else
   57.13 +/*
   57.14 + * In debug builds we aggressively shadow PDPTs to exercise code paths.
   57.15 + * We cannot safely shadow the idle page table, nor shadow-mode page tables
   57.16 + * (detected by lack of an owning domain). Always shadow PDPTs above 4GB.
   57.17 + */
   57.18 +#define l3tab_needs_shadow(mfn)                         \
   57.19 +    ((((mfn << PAGE_SHIFT) != __pa(idle_pg_table)) &&   \
   57.20 +      (page_get_owner(mfn_to_page(mfn)) != NULL)) ||    \
   57.21 +     (mfn >= 0x100000))
   57.22 +#endif
   57.23 +
   57.24 +static l1_pgentry_t *fix_pae_highmem_pl1e;
   57.25 +
   57.26 +/* Cache the address of PAE high-memory fixmap page tables. */
   57.27 +static int __init cache_pae_fixmap_address(void)
   57.28 +{
   57.29 +    unsigned long fixmap_base = fix_to_virt(FIX_PAE_HIGHMEM_0);
   57.30 +    l2_pgentry_t *pl2e = virt_to_xen_l2e(fixmap_base);
   57.31 +    fix_pae_highmem_pl1e = l2e_to_l1e(*pl2e) + l1_table_offset(fixmap_base);
   57.32 +    return 0;
   57.33 +}
   57.34 +__initcall(cache_pae_fixmap_address);
   57.35 +
   57.36  static void __write_ptbase(unsigned long mfn)
   57.37  {
   57.38 -#ifdef CONFIG_X86_PAE
   57.39 -    if ( mfn >= 0x100000 )
   57.40 +    l3_pgentry_t *highmem_l3tab, *lowmem_l3tab;
   57.41 +    struct pae_l3_cache *cache = &current->arch.pae_l3_cache;
   57.42 +    unsigned int cpu = smp_processor_id();
   57.43 +
   57.44 +    /* Fast path 1: does this mfn need a shadow at all? */
   57.45 +    if ( !l3tab_needs_shadow(mfn) )
   57.46      {
   57.47 -        l3_pgentry_t *highmem_l3tab, *lowmem_l3tab;
   57.48 -        struct vcpu *v = current;
   57.49 -        unsigned long flags;
   57.50 -
   57.51 -        /* Protects against re-entry and against __pae_flush_pgd(). */
   57.52 -        local_irq_save(flags);
   57.53 -
   57.54 -        /* Pick an unused low-memory L3 cache slot. */
   57.55 -        v->arch.lowmem_l3tab_inuse ^= 1;
   57.56 -        lowmem_l3tab = v->arch.lowmem_l3tab[v->arch.lowmem_l3tab_inuse];
   57.57 -        v->arch.lowmem_l3tab_high_mfn[v->arch.lowmem_l3tab_inuse] = mfn;
   57.58 -
   57.59 -        /* Map the guest L3 table and copy to the chosen low-memory cache. */
   57.60 -        highmem_l3tab = map_domain_page(mfn);
   57.61 -        memcpy(lowmem_l3tab, highmem_l3tab, sizeof(v->arch.lowmem_l3tab));
   57.62 -        unmap_domain_page(highmem_l3tab);
   57.63 -
   57.64 -        /* Install the low-memory L3 table in CR3. */
   57.65 -        write_cr3(__pa(lowmem_l3tab));
   57.66 -
   57.67 -        local_irq_restore(flags);
   57.68 +        write_cr3(mfn << PAGE_SHIFT);
   57.69 +        return;
   57.70 +    }
   57.71 +
   57.72 +    /* Caching logic is not interrupt safe. */
   57.73 +    ASSERT(!in_irq());
   57.74 +
   57.75 +    /* Fast path 2: is this mfn already cached? */
   57.76 +    if ( cache->high_mfn == mfn )
   57.77 +    {
   57.78 +        write_cr3(__pa(cache->table[cache->inuse_idx]));
   57.79          return;
   57.80      }
   57.81 -#endif
   57.82 -
   57.83 +
   57.84 +    /* Protects against pae_flush_pgd(). */
   57.85 +    spin_lock(&cache->lock);
   57.86 +
   57.87 +    cache->inuse_idx ^= 1;
   57.88 +    cache->high_mfn   = mfn;
   57.89 +
   57.90 +    /* Map the guest L3 table and copy to the chosen low-memory cache. */
   57.91 +    *(fix_pae_highmem_pl1e - cpu) = l1e_from_pfn(mfn, __PAGE_HYPERVISOR);
   57.92 +    highmem_l3tab = (l3_pgentry_t *)fix_to_virt(FIX_PAE_HIGHMEM_0 + cpu);
   57.93 +    lowmem_l3tab  = cache->table[cache->inuse_idx];
   57.94 +    memcpy(lowmem_l3tab, highmem_l3tab, sizeof(cache->table[0]));
   57.95 +    *(fix_pae_highmem_pl1e - cpu) = l1e_empty();
   57.96 +
   57.97 +    /* Install the low-memory L3 table in CR3. */
   57.98 +    write_cr3(__pa(lowmem_l3tab));
   57.99 +
  57.100 +    spin_unlock(&cache->lock);
  57.101 +}
  57.102 +
  57.103 +#else /* !CONFIG_X86_PAE */
  57.104 +
  57.105 +static void __write_ptbase(unsigned long mfn)
  57.106 +{
  57.107      write_cr3(mfn << PAGE_SHIFT);
  57.108  }
  57.109  
  57.110 +#endif /* !CONFIG_X86_PAE */
  57.111 +
  57.112  void write_ptbase(struct vcpu *v)
  57.113  {
  57.114      __write_ptbase(pagetable_get_pfn(v->arch.monitor_table));
  57.115 @@ -804,48 +851,39 @@ static int create_pae_xen_mappings(l3_pg
  57.116      return 1;
  57.117  }
  57.118  
  57.119 -struct pae_flush_pgd {
  57.120 -    unsigned long l3tab_mfn;
  57.121 -    unsigned int  l3tab_idx;
  57.122 -    l3_pgentry_t  nl3e;
  57.123 -};
  57.124 -
  57.125 -static void __pae_flush_pgd(void *data)
  57.126 -{
  57.127 -    struct pae_flush_pgd *args = data;
  57.128 -    struct vcpu *v = this_cpu(curr_vcpu);
  57.129 -    int i = v->arch.lowmem_l3tab_inuse;
  57.130 -    intpte_t _ol3e, _nl3e, _pl3e;
  57.131 -    l3_pgentry_t *l3tab_ptr;
  57.132 -
  57.133 -    ASSERT(!local_irq_is_enabled());
  57.134 -
  57.135 -    if ( v->arch.lowmem_l3tab_high_mfn[i] != args->l3tab_mfn )
  57.136 -        return;
  57.137 -
  57.138 -    l3tab_ptr = &v->arch.lowmem_l3tab[i][args->l3tab_idx];
  57.139 -
  57.140 -    _ol3e = l3e_get_intpte(*l3tab_ptr);
  57.141 -    _nl3e = l3e_get_intpte(args->nl3e);
  57.142 -    _pl3e = cmpxchg((intpte_t *)l3tab_ptr, _ol3e, _nl3e);
  57.143 -    BUG_ON(_pl3e != _ol3e);
  57.144 -}
  57.145 -
  57.146  /* Flush a pgdir update into low-memory caches. */
  57.147  static void pae_flush_pgd(
  57.148      unsigned long mfn, unsigned int idx, l3_pgentry_t nl3e)
  57.149  {
  57.150      struct domain *d = page_get_owner(mfn_to_page(mfn));
  57.151 -    struct pae_flush_pgd args = {
  57.152 -        .l3tab_mfn = mfn,
  57.153 -        .l3tab_idx = idx,
  57.154 -        .nl3e      = nl3e };
  57.155 +    struct vcpu   *v;
  57.156 +    intpte_t       _ol3e, _nl3e, _pl3e;
  57.157 +    l3_pgentry_t  *l3tab_ptr;
  57.158 +    struct pae_l3_cache *cache;
  57.159  
  57.160      /* If below 4GB then the pgdir is not shadowed in low memory. */
  57.161 -    if ( mfn < 0x100000 )
  57.162 +    if ( !l3tab_needs_shadow(mfn) )
  57.163          return;
  57.164  
  57.165 -    on_selected_cpus(d->domain_dirty_cpumask, __pae_flush_pgd, &args, 1, 1);
  57.166 +    for_each_vcpu ( d, v )
  57.167 +    {
  57.168 +        cache = &v->arch.pae_l3_cache;
  57.169 +
  57.170 +        spin_lock(&cache->lock);
  57.171 +
  57.172 +        if ( cache->high_mfn == mfn )
  57.173 +        {
  57.174 +            l3tab_ptr = &cache->table[cache->inuse_idx][idx];
  57.175 +            _ol3e = l3e_get_intpte(*l3tab_ptr);
  57.176 +            _nl3e = l3e_get_intpte(nl3e);
  57.177 +            _pl3e = cmpxchg((intpte_t *)l3tab_ptr, _ol3e, _nl3e);
  57.178 +            BUG_ON(_pl3e != _ol3e);
  57.179 +        }
  57.180 +
  57.181 +        spin_unlock(&cache->lock);
  57.182 +    }
  57.183 +
  57.184 +    flush_tlb_mask(d->domain_dirty_cpumask);
  57.185  }
  57.186  
  57.187  static inline int l1_backptr(
  57.188 @@ -1567,12 +1605,18 @@ int get_page_type(struct page_info *page
  57.189              {
  57.190                  if ( unlikely((x & PGT_type_mask) != (type & PGT_type_mask) ) )
  57.191                  {
  57.192 -                    if ( current->domain == page_get_owner(page) )
  57.193 +                    if ( (current->domain == page_get_owner(page)) &&
  57.194 +                         ((x & PGT_type_mask) == PGT_writable_page) )
  57.195                      {
  57.196                          /*
  57.197                           * This ensures functions like set_gdt() see up-to-date
  57.198                           * type info without needing to clean up writable p.t.
  57.199 -                         * state on the fast path.
  57.200 +                         * state on the fast path. We take this path only
  57.201 +                         * when the current type is writable because:
  57.202 +                         *  1. It's the only type that this path can decrement.
  57.203 +                         *  2. If we take this path more liberally then we can
  57.204 +                         *     enter a recursive loop via get_page_from_l1e()
  57.205 +                         *     during pagetable revalidation.
  57.206                           */
  57.207                          LOCK_BIGLOCK(current->domain);
  57.208                          cleanup_writable_pagetable(current->domain);
  57.209 @@ -3708,11 +3752,10 @@ int map_pages_to_xen(
  57.210  }
  57.211  
  57.212  void __set_fixmap(
  57.213 -    enum fixed_addresses idx, unsigned long p, unsigned long flags)
  57.214 +    enum fixed_addresses idx, unsigned long mfn, unsigned long flags)
  57.215  {
  57.216 -    if ( unlikely(idx >= __end_of_fixed_addresses) )
  57.217 -        BUG();
  57.218 -    map_pages_to_xen(fix_to_virt(idx), p >> PAGE_SHIFT, 1, flags);
  57.219 +    BUG_ON(idx >= __end_of_fixed_addresses);
  57.220 +    map_pages_to_xen(fix_to_virt(idx), mfn, 1, flags);
  57.221  }
  57.222  
  57.223  #ifdef MEMORY_GUARD
    58.1 --- a/xen/arch/x86/shadow.c	Wed May 31 11:30:07 2006 -0600
    58.2 +++ b/xen/arch/x86/shadow.c	Wed May 31 13:05:21 2006 -0600
    58.3 @@ -1724,7 +1724,8 @@ static int resync_all(struct domain *d, 
    58.4                          unshadow_l1 = 1;
    58.5                      else {
    58.6                          need_flush |= error;
    58.7 -                        set_guest_back_ptr(d, *sl1e_p, smfn, i);
    58.8 +                        if ( l1e_get_flags(*sl1e_p) & _PAGE_PRESENT )
    58.9 +                            set_guest_back_ptr(d, *sl1e_p, smfn, i);
   58.10                      }
   58.11                      // can't update snapshots of linear page tables -- they
   58.12                      // are used multiple times...
    59.1 --- a/xen/arch/x86/shadow32.c	Wed May 31 11:30:07 2006 -0600
    59.2 +++ b/xen/arch/x86/shadow32.c	Wed May 31 13:05:21 2006 -0600
    59.3 @@ -2691,7 +2691,8 @@ static int resync_all(struct domain *d, 
    59.4                          unshadow_l1 = 1;
    59.5                      else {
    59.6                          need_flush |= error;
    59.7 -                        set_guest_back_ptr(d, shadow1[i], smfn, i);
    59.8 +                        if ( l1e_get_flags(shadow1[i]) & _PAGE_PRESENT )
    59.9 +                            set_guest_back_ptr(d, shadow1[i], smfn, i);
   59.10                      }
   59.11  
   59.12                      // can't update snapshots of linear page tables -- they
    60.1 --- a/xen/include/asm-x86/domain.h	Wed May 31 11:30:07 2006 -0600
    60.2 +++ b/xen/include/asm-x86/domain.h	Wed May 31 13:05:21 2006 -0600
    60.3 @@ -114,23 +114,32 @@ struct arch_domain
    60.4      unsigned long first_reserved_pfn;
    60.5  } __cacheline_aligned;
    60.6  
    60.7 +#ifdef CONFIG_X86_PAE
    60.8 +struct pae_l3_cache {
    60.9 +    /*
   60.10 +     * Two low-memory (<4GB) PAE L3 tables, used as fallback when the guest
   60.11 +     * supplies a >=4GB PAE L3 table. We need two because we cannot set up
   60.12 +     * an L3 table while we are currently running on it (without using
   60.13 +     * expensive atomic 64-bit operations).
   60.14 +     */
   60.15 +    l3_pgentry_t  table[2][4] __attribute__((__aligned__(32)));
   60.16 +    unsigned long high_mfn;  /* The >=4GB MFN being shadowed. */
   60.17 +    unsigned int  inuse_idx; /* Which of the two cache slots is in use? */
   60.18 +    spinlock_t    lock;
   60.19 +};
   60.20 +#define pae_l3_cache_init(c) spin_lock_init(&(c)->lock)
   60.21 +#else /* !CONFIG_X86_PAE */
   60.22 +struct pae_l3_cache { };
   60.23 +#define pae_l3_cache_init(c) ((void)0)
   60.24 +#endif
   60.25 +
   60.26  struct arch_vcpu
   60.27  {
   60.28      /* Needs 16-byte aligment for FXSAVE/FXRSTOR. */
   60.29      struct vcpu_guest_context guest_context
   60.30      __attribute__((__aligned__(16)));
   60.31  
   60.32 -#ifdef CONFIG_X86_PAE
   60.33 -    /*
   60.34 -     * Two low-memory (<4GB) PAE L3 tables, used as fallback when the guest
   60.35 -     * supplies a >=4GB PAE L3 table. We need two because we cannot set up
   60.36 -     * an L3 table while we are currently running on it (without using
   60.37 -     * expensive atomic 64-bit operations).
   60.38 -     */
   60.39 -    l3_pgentry_t  lowmem_l3tab[2][4] __attribute__((__aligned__(32)));
   60.40 -    unsigned long lowmem_l3tab_high_mfn[2]; /* The >=4GB MFN being shadowed. */
   60.41 -    unsigned int  lowmem_l3tab_inuse;       /* Which lowmem_l3tab is in use? */
   60.42 -#endif
   60.43 +    struct pae_l3_cache pae_l3_cache;
   60.44  
   60.45      unsigned long      flags; /* TF_ */
   60.46  
    61.1 --- a/xen/include/asm-x86/fixmap.h	Wed May 31 11:30:07 2006 -0600
    61.2 +++ b/xen/include/asm-x86/fixmap.h	Wed May 31 13:05:21 2006 -0600
    61.3 @@ -25,6 +25,10 @@
    61.4   * from the end of virtual memory backwards.
    61.5   */
    61.6  enum fixed_addresses {
    61.7 +#ifdef CONFIG_X86_PAE
    61.8 +    FIX_PAE_HIGHMEM_0,
    61.9 +    FIX_PAE_HIGHMEM_END = FIX_PAE_HIGHMEM_0 + NR_CPUS-1,
   61.10 +#endif
   61.11      FIX_APIC_BASE,
   61.12      FIX_IO_APIC_BASE_0,
   61.13      FIX_IO_APIC_BASE_END = FIX_IO_APIC_BASE_0 + MAX_IO_APICS-1,
   61.14 @@ -40,13 +44,13 @@ enum fixed_addresses {
   61.15  #define FIXADDR_START (FIXADDR_TOP - FIXADDR_SIZE)
   61.16  
   61.17  extern void __set_fixmap(
   61.18 -    enum fixed_addresses idx, unsigned long p, unsigned long flags);
   61.19 +    enum fixed_addresses idx, unsigned long mfn, unsigned long flags);
   61.20  
   61.21  #define set_fixmap(idx, phys) \
   61.22 -    __set_fixmap(idx, phys, PAGE_HYPERVISOR)
   61.23 +    __set_fixmap(idx, (phys)>>PAGE_SHIFT, PAGE_HYPERVISOR)
   61.24  
   61.25  #define set_fixmap_nocache(idx, phys) \
   61.26 -    __set_fixmap(idx, phys, PAGE_HYPERVISOR_NOCACHE)
   61.27 +    __set_fixmap(idx, (phys)>>PAGE_SHIFT, PAGE_HYPERVISOR_NOCACHE)
   61.28  
   61.29  #define __fix_to_virt(x) (FIXADDR_TOP - ((x) << PAGE_SHIFT))
   61.30  #define __virt_to_fix(x) ((FIXADDR_TOP - ((x)&PAGE_MASK)) >> PAGE_SHIFT)
    62.1 --- a/xen/include/asm-x86/shadow.h	Wed May 31 11:30:07 2006 -0600
    62.2 +++ b/xen/include/asm-x86/shadow.h	Wed May 31 13:05:21 2006 -0600
    62.3 @@ -762,10 +762,16 @@ static inline void set_guest_back_ptr(
    62.4          unsigned long gmfn;
    62.5  
    62.6          ASSERT(shadow_lock_is_acquired(d));
    62.7 +        ASSERT( smfn );
    62.8          gmfn = l1e_get_pfn(spte);
    62.9 -        mfn_to_page(gmfn)->tlbflush_timestamp = smfn;
   62.10 -        mfn_to_page(gmfn)->u.inuse.type_info &= ~PGT_va_mask;
   62.11 -        mfn_to_page(gmfn)->u.inuse.type_info |= (unsigned long) index << PGT_va_shift;
   62.12 +        ASSERT( gmfn );
   62.13 +        if ( l1e_get_flags(spte) & _PAGE_RW )
   62.14 +        {
   62.15 +            mfn_to_page(gmfn)->tlbflush_timestamp = smfn;
   62.16 +            mfn_to_page(gmfn)->u.inuse.type_info &= ~PGT_va_mask;
   62.17 +            mfn_to_page(gmfn)->u.inuse.type_info |= 
   62.18 +                (unsigned long) index << PGT_va_shift;
   62.19 +        }
   62.20      }
   62.21  }
   62.22  
    63.1 --- a/xen/include/public/sched_ctl.h	Wed May 31 11:30:07 2006 -0600
    63.2 +++ b/xen/include/public/sched_ctl.h	Wed May 31 13:05:21 2006 -0600
    63.3 @@ -49,7 +49,7 @@ struct sched_adjdom_cmd {
    63.4              uint32_t extratime;
    63.5              uint32_t weight;
    63.6          } sedf;
    63.7 -        struct csched_domain {
    63.8 +        struct sched_credit_adjdom {
    63.9              uint16_t weight;
   63.10              uint16_t cap;
   63.11          } credit;
    64.1 --- a/xen/include/xen/perfc.h	Wed May 31 11:30:07 2006 -0600
    64.2 +++ b/xen/include/xen/perfc.h	Wed May 31 13:05:21 2006 -0600
    64.3 @@ -56,10 +56,8 @@ extern struct perfcounter perfcounters;
    64.4  #define perfc_value(x)    atomic_read(&perfcounters.x[0])
    64.5  #define perfc_valuec(x)   atomic_read(&perfcounters.x[smp_processor_id()])
    64.6  #define perfc_valuea(x,y)                                               \
    64.7 -    do {                                                                \
    64.8 -        if ( (y) < (sizeof(perfcounters.x) / sizeof(*perfcounters.x)) ) \
    64.9 -            atomic_read(&perfcounters.x[y]);                            \
   64.10 -    } while ( 0 )
   64.11 +    ( (y) < (sizeof(perfcounters.x) / sizeof(*perfcounters.x)) ?	\
   64.12 +	atomic_read(&perfcounters.x[y]) : 0 )
   64.13  #define perfc_set(x,v)    atomic_set(&perfcounters.x[0], v)
   64.14  #define perfc_setc(x,v)   atomic_set(&perfcounters.x[smp_processor_id()], v)
   64.15  #define perfc_seta(x,y,v)                                               \
    65.1 --- a/xen/tools/Makefile	Wed May 31 11:30:07 2006 -0600
    65.2 +++ b/xen/tools/Makefile	Wed May 31 13:05:21 2006 -0600
    65.3 @@ -1,5 +1,6 @@
    65.4  
    65.5 -include $(BASEDIR)/../Config.mk
    65.6 +XEN_ROOT = $(BASEDIR)/..
    65.7 +include $(XEN_ROOT)/Config.mk
    65.8  
    65.9  .PHONY: default
   65.10  default:
    66.1 --- a/xen/tools/figlet/Makefile	Wed May 31 11:30:07 2006 -0600
    66.2 +++ b/xen/tools/figlet/Makefile	Wed May 31 13:05:21 2006 -0600
    66.3 @@ -1,5 +1,6 @@
    66.4  
    66.5 -include $(BASEDIR)/../Config.mk
    66.6 +XEN_ROOT = $(BASEDIR)/..
    66.7 +include $(XEN_ROOT)/Config.mk
    66.8  
    66.9  figlet: figlet.c
   66.10  	$(HOSTCC) -o $@ $<