Xen 
 
Home About Xen.org Xen Xen Summit Wiki Mailing List Bug Tracker Xen Downloads
 
   
 

xen-changelog

[Xen-changelog] Merged.

# HG changeset patch
# User emellor@xxxxxxxxxxxxxxxxxxxxxx
# Node ID bcccadcc56e5bd460fcffdb4931652ebac928276
# Parent  dc36edf1102fd8dc3638f1a2f0bd7f38cb97e8c3
# Parent  b5903c9aeda56523b6676163e06b7db5cf4cd93d
Merged.

diff -r dc36edf1102f -r bcccadcc56e5 extras/mini-os/include/events.h
--- a/extras/mini-os/include/events.h   Sun Oct 30 12:52:38 2005
+++ b/extras/mini-os/include/events.h   Sun Oct 30 13:00:35 2005
@@ -47,7 +47,7 @@
 {
     evtchn_op_t op;
     op.cmd = EVTCHNOP_send;
-    op.u.send.local_port = port;
+    op.u.send.port = port;
     return HYPERVISOR_event_channel_op(&op);
 }
 
diff -r dc36edf1102f -r bcccadcc56e5 extras/mini-os/include/hypervisor.h
--- a/extras/mini-os/include/hypervisor.h       Sun Oct 30 12:52:38 2005
+++ b/extras/mini-os/include/hypervisor.h       Sun Oct 30 13:00:35 2005
@@ -14,6 +14,7 @@
 
 #include <types.h>
 #include <xen/xen.h>
+#include <xen/dom0_ops.h>
 
 /*
  * a placeholder for the start of day information passed up from the hypervisor
@@ -37,548 +38,281 @@
  * Assembler stubs for hyper-calls.
  */
 #if defined(__i386__)
+/* Taken from Linux */
+
+#ifndef __HYPERCALL_H__
+#define __HYPERCALL_H__
+
+#include <xen/sched.h>
+
+#define _hypercall0(type, name)                        \
+({                                             \
+       long __res;                             \
+       asm volatile (                          \
+               TRAP_INSTR                      \
+               : "=a" (__res)                  \
+               : "0" (__HYPERVISOR_##name)     \
+               : "memory" );                   \
+       (type)__res;                            \
+})
+
+#define _hypercall1(type, name, a1)                            \
+({                                                             \
+       long __res, __ign1;                                     \
+       asm volatile (                                          \
+               TRAP_INSTR                                      \
+               : "=a" (__res), "=b" (__ign1)                   \
+               : "0" (__HYPERVISOR_##name), "1" ((long)(a1))   \
+               : "memory" );                                   \
+       (type)__res;                                            \
+})
+
+#define _hypercall2(type, name, a1, a2)                                \
+({                                                             \
+       long __res, __ign1, __ign2;                             \
+       asm volatile (                                          \
+               TRAP_INSTR                                      \
+               : "=a" (__res), "=b" (__ign1), "=c" (__ign2)    \
+               : "0" (__HYPERVISOR_##name), "1" ((long)(a1)),  \
+               "2" ((long)(a2))                                \
+               : "memory" );                                   \
+       (type)__res;                                            \
+})
+
+#define _hypercall3(type, name, a1, a2, a3)                    \
+({                                                             \
+       long __res, __ign1, __ign2, __ign3;                     \
+       asm volatile (                                          \
+               TRAP_INSTR                                      \
+               : "=a" (__res), "=b" (__ign1), "=c" (__ign2),   \
+               "=d" (__ign3)                                   \
+               : "0" (__HYPERVISOR_##name), "1" ((long)(a1)),  \
+               "2" ((long)(a2)), "3" ((long)(a3))              \
+               : "memory" );                                   \
+       (type)__res;                                            \
+})
+
+#define _hypercall4(type, name, a1, a2, a3, a4)                        \
+({                                                             \
+       long __res, __ign1, __ign2, __ign3, __ign4;             \
+       asm volatile (                                          \
+               TRAP_INSTR                                      \
+               : "=a" (__res), "=b" (__ign1), "=c" (__ign2),   \
+               "=d" (__ign3), "=S" (__ign4)                    \
+               : "0" (__HYPERVISOR_##name), "1" ((long)(a1)),  \
+               "2" ((long)(a2)), "3" ((long)(a3)),             \
+               "4" ((long)(a4))                                \
+               : "memory" );                                   \
+       (type)__res;                                            \
+})
+
+#define _hypercall5(type, name, a1, a2, a3, a4, a5)            \
+({                                                             \
+       long __res, __ign1, __ign2, __ign3, __ign4, __ign5;     \
+       asm volatile (                                          \
+               TRAP_INSTR                                      \
+               : "=a" (__res), "=b" (__ign1), "=c" (__ign2),   \
+               "=d" (__ign3), "=S" (__ign4), "=D" (__ign5)     \
+               : "0" (__HYPERVISOR_##name), "1" ((long)(a1)),  \
+               "2" ((long)(a2)), "3" ((long)(a3)),             \
+               "4" ((long)(a4)), "5" ((long)(a5))              \
+               : "memory" );                                   \
+       (type)__res;                                            \
+})
+
 static inline int
 HYPERVISOR_set_trap_table(
-    trap_info_t *table)
-{
-    int ret;
-    unsigned long ignore;
-
-    __asm__ __volatile__ (
-        TRAP_INSTR
-        : "=a" (ret), "=b" (ignore)
-       : "0" (__HYPERVISOR_set_trap_table), "1" (table)
-       : "memory" );
-
-    return ret;
+       trap_info_t *table)
+{
+       return _hypercall1(int, set_trap_table, table);
 }
 
 static inline int
 HYPERVISOR_mmu_update(
-    mmu_update_t *req, int count, int *success_count, domid_t domid)
-{
-    int ret;
-    unsigned long ign1, ign2, ign3, ign4;
-
-    __asm__ __volatile__ (
-        TRAP_INSTR
-        : "=a" (ret), "=b" (ign1), "=c" (ign2), "=d" (ign3), "=S" (ign4)
-       : "0" (__HYPERVISOR_mmu_update), "1" (req), "2" (count),
-        "3" (success_count), "4" (domid)
-       : "memory" );
-
-    return ret;
+       mmu_update_t *req, int count, int *success_count, domid_t domid)
+{
+       return _hypercall4(int, mmu_update, req, count, success_count, domid);
 }
 
 static inline int
 HYPERVISOR_mmuext_op(
-    struct mmuext_op *op, int count, int *success_count, domid_t domid)
-{
-    int ret;
-    unsigned long ign1, ign2, ign3, ign4;
-
-    __asm__ __volatile__ (
-        TRAP_INSTR
-        : "=a" (ret), "=b" (ign1), "=c" (ign2), "=d" (ign3), "=S" (ign4)
-       : "0" (__HYPERVISOR_mmuext_op), "1" (op), "2" (count),
-        "3" (success_count), "4" (domid)
-       : "memory" );
-
-    return ret;
+       struct mmuext_op *op, int count, int *success_count, domid_t domid)
+{
+       return _hypercall4(int, mmuext_op, op, count, success_count, domid);
 }
 
 static inline int
 HYPERVISOR_set_gdt(
-    unsigned long *frame_list, int entries)
-{
-    int ret;
-    unsigned long ign1, ign2;
-
-    __asm__ __volatile__ (
-        TRAP_INSTR
-        : "=a" (ret), "=b" (ign1), "=c" (ign2)
-       : "0" (__HYPERVISOR_set_gdt), "1" (frame_list), "2" (entries)
-       : "memory" );
-
-
-    return ret;
+       unsigned long *frame_list, int entries)
+{
+       return _hypercall2(int, set_gdt, frame_list, entries);
 }
 
 static inline int
 HYPERVISOR_stack_switch(
-    unsigned long ss, unsigned long esp)
-{
-    int ret;
-    unsigned long ign1, ign2;
-
-    __asm__ __volatile__ (
-        TRAP_INSTR
-        : "=a" (ret), "=b" (ign1), "=c" (ign2)
-       : "0" (__HYPERVISOR_stack_switch), "1" (ss), "2" (esp)
-       : "memory" );
-
-    return ret;
+       unsigned long ss, unsigned long esp)
+{
+       return _hypercall2(int, stack_switch, ss, esp);
 }
 
 static inline int
 HYPERVISOR_set_callbacks(
-    unsigned long event_selector, unsigned long event_address,
-    unsigned long failsafe_selector, unsigned long failsafe_address)
-{
-    int ret;
-    unsigned long ign1, ign2, ign3, ign4;
-
-    __asm__ __volatile__ (
-        TRAP_INSTR
-        : "=a" (ret), "=b" (ign1), "=c" (ign2), "=d" (ign3), "=S" (ign4)
-       : "0" (__HYPERVISOR_set_callbacks), "1" (event_selector),
-         "2" (event_address), "3" (failsafe_selector), "4" (failsafe_address)
-       : "memory" );
-
-    return ret;
+       unsigned long event_selector, unsigned long event_address,
+       unsigned long failsafe_selector, unsigned long failsafe_address)
+{
+       return _hypercall4(int, set_callbacks,
+                          event_selector, event_address,
+                          failsafe_selector, failsafe_address);
 }
 
 static inline int
 HYPERVISOR_fpu_taskswitch(
-    int set)
-{
-    int ret;
-    unsigned long ign;
-
-    __asm__ __volatile__ (
-        TRAP_INSTR
-        : "=a" (ret), "=b" (ign)
-        : "0" (__HYPERVISOR_fpu_taskswitch), "1" (set)
-        : "memory" );
-
-    return ret;
-}
-
-static inline int
-HYPERVISOR_yield(
-    void)
-{
-    int ret;
-    unsigned long ign;
-
-    __asm__ __volatile__ (
-        TRAP_INSTR
-        : "=a" (ret), "=b" (ign)
-       : "0" (__HYPERVISOR_sched_op), "1" (SCHEDOP_yield)
-       : "memory", "ecx" );
-
-    return ret;
-}
-
-static inline int
-HYPERVISOR_block(
-    void)
-{
-    int ret;
-    unsigned long ign1;
-    __asm__ __volatile__ (
-        TRAP_INSTR
-        : "=a" (ret), "=b" (ign1)
-       : "0" (__HYPERVISOR_sched_op), "1" (SCHEDOP_block)
-       : "memory", "ecx" );
-
-    return ret;
-}
-
-static inline int
-HYPERVISOR_shutdown(
-    void)
-{
-    int ret;
-    unsigned long ign1;
-    __asm__ __volatile__ (
-        TRAP_INSTR
-        : "=a" (ret), "=b" (ign1)
-       : "0" (__HYPERVISOR_sched_op),
-         "1" (SCHEDOP_shutdown | (SHUTDOWN_poweroff << SCHEDOP_reasonshift))
-        : "memory", "ecx" );
-
-    return ret;
-}
-
-static inline int
-HYPERVISOR_reboot(
-    void)
-{
-    int ret;
-    unsigned long ign1;
-    __asm__ __volatile__ (
-        TRAP_INSTR
-        : "=a" (ret), "=b" (ign1)
-       : "0" (__HYPERVISOR_sched_op),
-         "1" (SCHEDOP_shutdown | (SHUTDOWN_reboot << SCHEDOP_reasonshift))
-        : "memory", "ecx" );
-
-    return ret;
-}
-
-static inline int
-HYPERVISOR_suspend(
-    unsigned long srec)
-{
-    int ret;
-    unsigned long ign1, ign2;
-
-    /* NB. On suspend, control software expects a suspend record in %esi. */
-    __asm__ __volatile__ (
-        TRAP_INSTR
-        : "=a" (ret), "=b" (ign1), "=S" (ign2)
-       : "0" (__HYPERVISOR_sched_op),
-        "b" (SCHEDOP_shutdown | (SHUTDOWN_suspend << SCHEDOP_reasonshift)), 
-        "S" (srec) : "memory", "ecx");
-
-    return ret;
-}
-
-static inline int
-HYPERVISOR_crash(
-    void)
-{
-    int ret;
-    unsigned long ign1;
-    __asm__ __volatile__ (
-        TRAP_INSTR
-        : "=a" (ret), "=b" (ign1)
-       : "0" (__HYPERVISOR_sched_op),
-         "1" (SCHEDOP_shutdown | (SHUTDOWN_crash << SCHEDOP_reasonshift))
-        : "memory", "ecx" );
-
-    return ret;
+       int set)
+{
+       return _hypercall1(int, fpu_taskswitch, set);
+}
+
+static inline int
+HYPERVISOR_sched_op(
+       int cmd, unsigned long arg)
+{
+       return _hypercall2(int, sched_op, cmd, arg);
 }
 
 static inline long
 HYPERVISOR_set_timer_op(
-    u64 timeout)
-{
-    int ret;
-    unsigned long timeout_hi = (unsigned long)(timeout>>32);
-    unsigned long timeout_lo = (unsigned long)timeout;
-    unsigned long ign1, ign2;
-
-    __asm__ __volatile__ (
-        TRAP_INSTR
-        : "=a" (ret), "=b" (ign1), "=c" (ign2)
-       : "0" (__HYPERVISOR_set_timer_op), "b" (timeout_lo), "c" (timeout_hi)
-       : "memory");
-
-    return ret;
-}
-
-#if 0
+       u64 timeout)
+{
+       unsigned long timeout_hi = (unsigned long)(timeout>>32);
+       unsigned long timeout_lo = (unsigned long)timeout;
+       return _hypercall2(long, set_timer_op, timeout_lo, timeout_hi);
+}
+
 static inline int
 HYPERVISOR_dom0_op(
-    dom0_op_t *dom0_op)
-{
-    int ret;
-    unsigned long ign1;
-
-    dom0_op->interface_version = DOM0_INTERFACE_VERSION;
-    __asm__ __volatile__ (
-        TRAP_INSTR
-        : "=a" (ret), "=b" (ign1)
-       : "0" (__HYPERVISOR_dom0_op), "1" (dom0_op)
-       : "memory");
-
-    return ret;
-}
-#endif
+       dom0_op_t *dom0_op)
+{
+       dom0_op->interface_version = DOM0_INTERFACE_VERSION;
+       return _hypercall1(int, dom0_op, dom0_op);
+}
 
 static inline int
 HYPERVISOR_set_debugreg(
-    int reg, unsigned long value)
-{
-    int ret;
-    unsigned long ign1, ign2;
-    __asm__ __volatile__ (
-        TRAP_INSTR
-        : "=a" (ret), "=b" (ign1), "=c" (ign2)
-       : "0" (__HYPERVISOR_set_debugreg), "1" (reg), "2" (value)
-       : "memory" );
-
-    return ret;
+       int reg, unsigned long value)
+{
+       return _hypercall2(int, set_debugreg, reg, value);
 }
 
 static inline unsigned long
 HYPERVISOR_get_debugreg(
-    int reg)
-{
-    unsigned long ret;
-    unsigned long ign;
-    __asm__ __volatile__ (
-        TRAP_INSTR
-        : "=a" (ret), "=b" (ign)
-       : "0" (__HYPERVISOR_get_debugreg), "1" (reg)
-       : "memory" );
-
-    return ret;
+       int reg)
+{
+       return _hypercall1(unsigned long, get_debugreg, reg);
 }
 
 static inline int
 HYPERVISOR_update_descriptor(
-    u64 ma, u64 desc)
-{
-    int ret;
-    unsigned long ign1, ign2, ign3, ign4;
-
-    __asm__ __volatile__ (
-        TRAP_INSTR
-        : "=a" (ret), "=b" (ign1), "=c" (ign2), "=d" (ign3), "=S" (ign4)
-       : "0" (__HYPERVISOR_update_descriptor),
-         "1" ((unsigned long)ma), "2" ((unsigned long)(ma>>32)),
-         "3" ((unsigned long)desc), "4" ((unsigned long)(desc>>32))
-       : "memory" );
-
-    return ret;
-}
-
-static inline int
-HYPERVISOR_dom_mem_op(
-    unsigned int op, unsigned long *extent_list,
-    unsigned long nr_extents, unsigned int extent_order)
-{
-    int ret;
-    unsigned long ign1, ign2, ign3, ign4, ign5;
-
-    __asm__ __volatile__ (
-        TRAP_INSTR
-        : "=a" (ret), "=b" (ign1), "=c" (ign2), "=d" (ign3), "=S" (ign4),
-         "=D" (ign5)
-       : "0" (__HYPERVISOR_dom_mem_op), "1" (op), "2" (extent_list),
-         "3" (nr_extents), "4" (extent_order), "5" (DOMID_SELF)
-        : "memory" );
-
-    return ret;
+       u64 ma, u64 desc)
+{
+       return _hypercall4(int, update_descriptor, ma, ma>>32, desc, desc>>32);
+}
+
+static inline int
+HYPERVISOR_memory_op(
+       unsigned int cmd, void *arg)
+{
+       return _hypercall2(int, memory_op, cmd, arg);
 }
 
 static inline int
 HYPERVISOR_multicall(
-    void *call_list, int nr_calls)
-{
-    int ret;
-    unsigned long ign1, ign2;
-
-    __asm__ __volatile__ (
-        TRAP_INSTR
-        : "=a" (ret), "=b" (ign1), "=c" (ign2)
-       : "0" (__HYPERVISOR_multicall), "1" (call_list), "2" (nr_calls)
-       : "memory" );
-
-    return ret;
+       void *call_list, int nr_calls)
+{
+       return _hypercall2(int, multicall, call_list, nr_calls);
 }
 
 static inline int
 HYPERVISOR_update_va_mapping(
-    unsigned long va, pte_t new_val, unsigned long flags)
-{
-    int ret;
-    unsigned long ign1, ign2, ign3, ign4;
-
-    __asm__ __volatile__ (
-        TRAP_INSTR
-        : "=a" (ret), "=b" (ign1), "=c" (ign2), "=d" (ign3), "=S" (ign4)
-       : "0" (__HYPERVISOR_update_va_mapping), 
-          "1" (va), "2" ((new_val).pte_low),
+       unsigned long va, pte_t new_val, unsigned long flags)
+{
+       unsigned long pte_hi = 0;
 #ifdef CONFIG_X86_PAE
-         "3" ((new_val).pte_high),
-#else
-         "3" (0),
+       pte_hi = new_val.pte_high;
 #endif
-         "4" (flags)
-       : "memory" );
-
-    return ret;
+       return _hypercall4(int, update_va_mapping, va,
+                          new_val.pte_low, pte_hi, flags);
 }
 
 static inline int
 HYPERVISOR_event_channel_op(
-    void *op)
-{
-    int ret;
-    unsigned long ignore;
-    __asm__ __volatile__ (
-        TRAP_INSTR
-        : "=a" (ret), "=b" (ignore)
-       : "0" (__HYPERVISOR_event_channel_op), "1" (op)
-       : "memory" );
-
-    return ret;
+       void *op)
+{
+       return _hypercall1(int, event_channel_op, op);
 }
 
 static inline int
 HYPERVISOR_xen_version(
-    int cmd, void *arg)
-{
-    int ret;
-    unsigned long ignore, ign2;
-
-    __asm__ __volatile__ (
-        TRAP_INSTR
-        : "=a" (ret), "=b" (ignore), "=c" (ign2)
-       : "0" (__HYPERVISOR_xen_version), "1" (cmd), "2" (arg)
-       : "memory" );
-
-    return ret;
+       int cmd, void *arg)
+{
+       return _hypercall2(int, xen_version, cmd, arg);
 }
 
 static inline int
 HYPERVISOR_console_io(
-    int cmd, int count, char *str)
-{
-    int ret;
-    unsigned long ign1, ign2, ign3;
-    __asm__ __volatile__ (
-        TRAP_INSTR
-        : "=a" (ret), "=b" (ign1), "=c" (ign2), "=d" (ign3)
-       : "0" (__HYPERVISOR_console_io), "1" (cmd), "2" (count), "3" (str)
-       : "memory" );
-
-    return ret;
+       int cmd, int count, char *str)
+{
+       return _hypercall3(int, console_io, cmd, count, str);
 }
 
 static inline int
 HYPERVISOR_physdev_op(
-    void *physdev_op)
-{
-    int ret;
-    unsigned long ign;
-
-    __asm__ __volatile__ (
-        TRAP_INSTR
-        : "=a" (ret), "=b" (ign)
-       : "0" (__HYPERVISOR_physdev_op), "1" (physdev_op)
-       : "memory" );
-
-    return ret;
+       void *physdev_op)
+{
+       return _hypercall1(int, physdev_op, physdev_op);
 }
 
 static inline int
 HYPERVISOR_grant_table_op(
-    unsigned int cmd, void *uop, unsigned int count)
-{
-    int ret;
-    unsigned long ign1, ign2, ign3;
-
-    __asm__ __volatile__ (
-        TRAP_INSTR
-        : "=a" (ret), "=b" (ign1), "=c" (ign2), "=d" (ign3)
-       : "0" (__HYPERVISOR_grant_table_op), "1" (cmd), "2" (uop), "3" (count)
-       : "memory" );
-
-    return ret;
+       unsigned int cmd, void *uop, unsigned int count)
+{
+       return _hypercall3(int, grant_table_op, cmd, uop, count);
 }
 
 static inline int
 HYPERVISOR_update_va_mapping_otherdomain(
-    unsigned long va, pte_t new_val, unsigned long flags, domid_t domid)
-{
-    int ret;
-    unsigned long ign1, ign2, ign3, ign4, ign5;
-
-    __asm__ __volatile__ (
-        TRAP_INSTR
-        : "=a" (ret), "=b" (ign1), "=c" (ign2), "=d" (ign3),
-         "=S" (ign4), "=D" (ign5)
-       : "0" (__HYPERVISOR_update_va_mapping_otherdomain),
-          "1" (va), "2" ((new_val).pte_low),
+       unsigned long va, pte_t new_val, unsigned long flags, domid_t domid)
+{
+       unsigned long pte_hi = 0;
 #ifdef CONFIG_X86_PAE
-         "3" ((new_val).pte_high),
-#else
-         "3" (0),
+       pte_hi = new_val.pte_high;
 #endif
-         "4" (flags), "5" (domid) :
-        "memory" );
-    
-    return ret;
+       return _hypercall5(int, update_va_mapping_otherdomain, va,
+                          new_val.pte_low, pte_hi, flags, domid);
 }
 
 static inline int
 HYPERVISOR_vm_assist(
-    unsigned int cmd, unsigned int type)
-{
-    int ret;
-    unsigned long ign1, ign2;
-
-    __asm__ __volatile__ (
-        TRAP_INSTR
-        : "=a" (ret), "=b" (ign1), "=c" (ign2)
-       : "0" (__HYPERVISOR_vm_assist), "1" (cmd), "2" (type)
-       : "memory" );
-
-    return ret;
-}
-
-static inline int
-HYPERVISOR_boot_vcpu(
-    unsigned long vcpu, vcpu_guest_context_t *ctxt)
-{
-    int ret;
-    unsigned long ign1, ign2;
-
-    __asm__ __volatile__ (
-        TRAP_INSTR
-        : "=a" (ret), "=b" (ign1), "=c" (ign2)
-       : "0" (__HYPERVISOR_boot_vcpu), "1" (vcpu), "2" (ctxt)
-       : "memory");
-
-    return ret;
-}
-
-static inline int
-HYPERVISOR_vcpu_down(
-    int vcpu)
-{
-    int ret;
-    unsigned long ign1;
-    /* Yes, I really do want to clobber edx here: when we resume a
-       vcpu after unpickling a multi-processor domain, it returns
-       here, but clobbers all of the call clobbered registers. */
-    __asm__ __volatile__ (
-        TRAP_INSTR
-        : "=a" (ret), "=b" (ign1)
-       : "0" (__HYPERVISOR_sched_op),
-         "1" (SCHEDOP_vcpu_down | (vcpu << SCHEDOP_vcpushift))
-        : "memory", "ecx", "edx" );
-
-    return ret;
-}
-
-static inline int
-HYPERVISOR_vcpu_up(
-    int vcpu)
-{
-    int ret;
-    unsigned long ign1;
-    __asm__ __volatile__ (
-        TRAP_INSTR
-        : "=a" (ret), "=b" (ign1)
-       : "0" (__HYPERVISOR_sched_op),
-         "1" (SCHEDOP_vcpu_up | (vcpu << SCHEDOP_vcpushift))
-        : "memory", "ecx" );
-
-    return ret;
-}
-
-static inline int
-HYPERVISOR_vcpu_pickle(
-    int vcpu, vcpu_guest_context_t *ctxt)
-{
-    int ret;
-    unsigned long ign1, ign2;
-    __asm__ __volatile__ (
-        TRAP_INSTR
-        : "=a" (ret), "=b" (ign1), "=c" (ign2)
-       : "0" (__HYPERVISOR_sched_op),
-         "1" (SCHEDOP_vcpu_pickle | (vcpu << SCHEDOP_vcpushift)),
-         "2" (ctxt)
-        : "memory" );
-
-    return ret;
-}
+       unsigned int cmd, unsigned int type)
+{
+       return _hypercall2(int, vm_assist, cmd, type);
+}
+
+static inline int
+HYPERVISOR_vcpu_op(
+       int cmd, int vcpuid, void *extra_args)
+{
+       return _hypercall3(int, vcpu_op, cmd, vcpuid, extra_args);
+}
+
+static inline int
+HYPERVISOR_suspend(
+       unsigned long srec)
+{
+       return _hypercall3(int, sched_op, SCHEDOP_shutdown,
+                          SHUTDOWN_suspend, srec);
+}
+
+#endif /* __HYPERCALL_H__ */
 #elif defined(__x86_64__)
 
 #define __syscall_clobber "r11","rcx","memory"
@@ -792,106 +526,4 @@
 }
 #endif
 
-
-static __inline__ int HYPERVISOR_dom0_op(void *dom0_op)
-{
-    int ret;
-    __asm__ __volatile__ (
-        TRAP_INSTR
-        : "=a" (ret) : "0" (__HYPERVISOR_dom0_op),
-        _a1 (dom0_op) : "memory" );
-
-    return ret;
-}
-
-static __inline__ int HYPERVISOR_set_debugreg(int reg, unsigned long value)
-{
-    int ret;
-    __asm__ __volatile__ (
-        TRAP_INSTR
-        : "=a" (ret) : "0" (__HYPERVISOR_set_debugreg),
-        _a1 (reg), _a2 (value) : "memory" );
-
-    return ret;
-}
-
-static __inline__ unsigned long HYPERVISOR_get_debugreg(int reg)
-{
-    unsigned long ret;
-    __asm__ __volatile__ (
-        TRAP_INSTR
-        : "=a" (ret) : "0" (__HYPERVISOR_get_debugreg),
-        _a1 (reg) : "memory" );
-
-    return ret;
-}
-
-static __inline__ int HYPERVISOR_update_descriptor(
-    unsigned long pa, unsigned long word1, unsigned long word2)
-{
-    int ret;
-    __asm__ __volatile__ (
-        TRAP_INSTR
-        : "=a" (ret) : "0" (__HYPERVISOR_update_descriptor), 
-        _a1 (pa), _a2 (word1), _a3 (word2) : "memory" );
-
-    return ret;
-}
-
-static __inline__ int HYPERVISOR_dom_mem_op(void *dom_mem_op)
-{
-    int ret;
-    __asm__ __volatile__ (
-        TRAP_INSTR
-        : "=a" (ret) : "0" (__HYPERVISOR_memory_op),
-        _a1 (dom_mem_op) : "memory" );
-
-    return ret;
-}
-
-static __inline__ int HYPERVISOR_multicall(void *call_list, int nr_calls)
-{
-    int ret;
-    __asm__ __volatile__ (
-        TRAP_INSTR
-        : "=a" (ret) : "0" (__HYPERVISOR_multicall),
-        _a1 (call_list), _a2 (nr_calls) : "memory" );
-
-    return ret;
-}
-
-static __inline__ int HYPERVISOR_update_va_mapping(
-    unsigned long page_nr, unsigned long new_val, unsigned long flags)
-{
-    int ret;
-    __asm__ __volatile__ (
-        TRAP_INSTR
-        : "=a" (ret) : "0" (__HYPERVISOR_update_va_mapping), 
-        _a1 (page_nr), _a2 (new_val), _a3 (flags) : "memory" );
-
-    return ret;
-}
-
-static __inline__ int HYPERVISOR_xen_version(int cmd)
-{
-    int ret;
-    __asm__ __volatile__ (
-        TRAP_INSTR
-        : "=a" (ret) : "0" (__HYPERVISOR_xen_version), 
-        _a1 (cmd) : "memory" );
-
-    return ret;
-}
-
-static __inline__ int HYPERVISOR_console_io(int cmd, int count, char *str)
-{
-    int ret;
-    __asm__ __volatile__ (
-        TRAP_INSTR
-        : "=a" (ret) : "0" (__HYPERVISOR_console_io),
-        _a1 (cmd), _a2 (count), _a3 (str) : "memory" );
-
-    return ret;
-}
-
 #endif /* __HYPERVISOR_H__ */
diff -r dc36edf1102f -r bcccadcc56e5 extras/mini-os/include/os.h
--- a/extras/mini-os/include/os.h       Sun Oct 30 12:52:38 2005
+++ b/extras/mini-os/include/os.h       Sun Oct 30 13:00:35 2005
@@ -24,7 +24,7 @@
 #include <xen/xen.h>
 
 
-#define force_evtchn_callback() ((void)HYPERVISOR_xen_version(0))
+#define force_evtchn_callback() ((void)HYPERVISOR_xen_version(0, 0))
 
 #define __KERNEL_CS  FLAT_KERNEL_CS
 #define __KERNEL_DS  FLAT_KERNEL_DS
@@ -55,6 +55,8 @@
 /* Everything below this point is not included by assembler (.S) files. */
 #ifndef __ASSEMBLY__
 
+extern shared_info_t *HYPERVISOR_shared_info;
+
 void trap_init(void);
 
 /* 
diff -r dc36edf1102f -r bcccadcc56e5 extras/mini-os/include/types.h
--- a/extras/mini-os/include/types.h    Sun Oct 30 12:52:38 2005
+++ b/extras/mini-os/include/types.h    Sun Oct 30 13:00:35 2005
@@ -54,7 +54,14 @@
 typedef struct { unsigned long pte; } pte_t;
 #endif
 
-
+typedef  u8 uint8_t;
+typedef  s8 int8_t;
+typedef u16 uint16_t;
+typedef s16 int16_t;
+typedef u32 uint32_t;
+typedef s32 int32_t;
+typedef u64 uint64_t;
+typedef s64 int64_t;
 
 
 #define INT_MAX         ((int)(~0U>>1))
diff -r dc36edf1102f -r bcccadcc56e5 extras/mini-os/kernel.c
--- a/extras/mini-os/kernel.c   Sun Oct 30 12:52:38 2005
+++ b/extras/mini-os/kernel.c   Sun Oct 30 13:00:35 2005
@@ -61,7 +61,7 @@
 
 extern char shared_info[PAGE_SIZE];
 
-#define __pte(x) ((pte_t) { (0) } )
+#define __pte(x) ((pte_t) { (x) } )
 
 static shared_info_t *map_shared_info(unsigned long pa)
 {
@@ -150,5 +150,5 @@
 void do_exit(void)
 {
     printk("do_exit called!\n");
-    for ( ;; ) HYPERVISOR_shutdown();
+    for ( ;; ) HYPERVISOR_sched_op(SCHEDOP_shutdown, SHUTDOWN_crash);
 }
diff -r dc36edf1102f -r bcccadcc56e5 extras/mini-os/time.c
--- a/extras/mini-os/time.c     Sun Oct 30 12:52:38 2005
+++ b/extras/mini-os/time.c     Sun Oct 30 13:00:35 2005
@@ -208,7 +208,7 @@
     struct timeval tv;
     gettimeofday(&tv);
     HYPERVISOR_set_timer_op(monotonic_clock() + 1000000LL * (s64) millisecs);
-    HYPERVISOR_block();
+    HYPERVISOR_sched_op(SCHEDOP_block, 0);
 }
 
 
diff -r dc36edf1102f -r bcccadcc56e5 extras/mini-os/xenbus/xenbus_xs.c
--- a/extras/mini-os/xenbus/xenbus_xs.c Sun Oct 30 12:52:38 2005
+++ b/extras/mini-os/xenbus/xenbus_xs.c Sun Oct 30 13:00:35 2005
@@ -39,7 +39,7 @@
 #include <wait.h>
 #include <sched.h>
 #include <semaphore.h>
-#include "xenstored.h"
+#include <xen/io/xs_wire.h>
 #include "xenbus_comms.h"
 
 #define streq(a, b) (strcmp((a), (b)) == 0)
@@ -408,7 +408,12 @@
 
 static int xs_acknowledge_watch(const char *token)
 {
+#if 0
        return xs_error(xs_single(XS_WATCH_ACK, token, NULL));
+#else
+       /* XS_WATCH_ACK is no longer available */
+       return 0;
+#endif
 }
 
 static int xs_unwatch(const char *path, const char *token)
diff -r dc36edf1102f -r bcccadcc56e5 
linux-2.6-xen-sparse/arch/ia64/xen/drivers/evtchn_ia64.c
--- a/linux-2.6-xen-sparse/arch/ia64/xen/drivers/evtchn_ia64.c  Sun Oct 30 
12:52:38 2005
+++ b/linux-2.6-xen-sparse/arch/ia64/xen/drivers/evtchn_ia64.c  Sun Oct 30 
13:00:35 2005
@@ -29,7 +29,7 @@
     return op.u.bind_virq.port;
 }
 
-int bind_virq_to_irq(int virq)
+int bind_virq_to_irq(int virq, int cpu)
 {
        printk("bind_virq_to_irq called... FIXME??\n");
        while(1);
@@ -66,7 +66,11 @@
     evtchns[evtchn].handler = handler;
     evtchns[evtchn].dev_id = dev_id;
     unmask_evtchn(evtchn);
-    return 0;
+    //return 0;
+    /* On ia64, there's only one irq vector allocated for all event channels,
+     * so let's just return evtchn as handle for later communication
+     */
+    return evtchn;
 }
 
 void unbind_evtchn_from_irqhandler(unsigned int evtchn, void *dev_id)
diff -r dc36edf1102f -r bcccadcc56e5 
linux-2.6-xen-sparse/arch/ia64/xen/xenentry.S
--- a/linux-2.6-xen-sparse/arch/ia64/xen/xenentry.S     Sun Oct 30 12:52:38 2005
+++ b/linux-2.6-xen-sparse/arch/ia64/xen/xenentry.S     Sun Oct 30 13:00:35 2005
@@ -46,8 +46,6 @@
        .prologue
        alloc r16=ar.pfs,1,0,0,0
 #endif
-       .prologue
-       alloc r16=ar.pfs,1,0,0,0
        DO_SAVE_SWITCH_STACK
        .body
 
diff -r dc36edf1102f -r bcccadcc56e5 
linux-2.6-xen-sparse/arch/xen/i386/kernel/entry.S
--- a/linux-2.6-xen-sparse/arch/xen/i386/kernel/entry.S Sun Oct 30 12:52:38 2005
+++ b/linux-2.6-xen-sparse/arch/xen/i386/kernel/entry.S Sun Oct 30 13:00:35 2005
@@ -653,7 +653,7 @@
 ENTRY(device_not_available)
        pushl $-1                       # mark this as an int
        SAVE_ALL
-       preempt_stop
+       #preempt_stop /* This is already an interrupt gate on Xen. */
        call math_state_restore
        jmp ret_from_exception
 
diff -r dc36edf1102f -r bcccadcc56e5 
linux-2.6-xen-sparse/arch/xen/i386/kernel/process.c
--- a/linux-2.6-xen-sparse/arch/xen/i386/kernel/process.c       Sun Oct 30 
12:52:38 2005
+++ b/linux-2.6-xen-sparse/arch/xen/i386/kernel/process.c       Sun Oct 30 
13:00:35 2005
@@ -483,6 +483,9 @@
                mcl->args[0] = 1;
                mcl++;
        }
+#if 0 /* lazy fpu sanity check */
+       else BUG_ON(!(read_cr0() & 8));
+#endif
 
        /*
         * Reload esp0, LDT and the page table pointer:
diff -r dc36edf1102f -r bcccadcc56e5 
linux-2.6-xen-sparse/arch/xen/i386/kernel/traps.c
--- a/linux-2.6-xen-sparse/arch/xen/i386/kernel/traps.c Sun Oct 30 12:52:38 2005
+++ b/linux-2.6-xen-sparse/arch/xen/i386/kernel/traps.c Sun Oct 30 13:00:35 2005
@@ -647,6 +647,12 @@
        do_trap(3, SIGTRAP, "int3", 1, regs, error_code, NULL);
 }
 #endif
+
+static inline void conditional_sti(struct pt_regs *regs)
+{
+       if ((uint8_t)(regs->xcs >> 16) == 0)
+               local_irq_enable();
+}
 
 /*
  * Our handling of the processor debug registers is non-trivial.
@@ -680,11 +686,9 @@
        if (notify_die(DIE_DEBUG, "debug", regs, condition, error_code,
                                        SIGTRAP) == NOTIFY_STOP)
                return;
-#if 0
+
        /* It's safe to allow irq's after DR6 has been saved */
-       if (regs->eflags & X86_EFLAGS_IF)
-               local_irq_enable();
-#endif
+       conditional_sti(regs);
 
        /* Mask out spurious debug traps due to lazy DR7 setting */
        if (condition & (DR_TRAP0|DR_TRAP1|DR_TRAP2|DR_TRAP3)) {
@@ -967,15 +971,18 @@
 #endif
 
 
-/* NB. All these are "trap gates" (i.e. events_mask isn't cleared). */
+/*
+ * NB. All these are "trap gates" (i.e. events_mask isn't cleared) except
+ * for those that specify <dpl>|4 in the second field.
+ */
 static trap_info_t trap_table[] = {
        {  0, 0, __KERNEL_CS, (unsigned long)divide_error               },
-       {  1, 0, __KERNEL_CS, (unsigned long)debug                      },
-       {  3, 3, __KERNEL_CS, (unsigned long)int3                       },
+       {  1, 0|4, __KERNEL_CS, (unsigned long)debug                    },
+       {  3, 3|4, __KERNEL_CS, (unsigned long)int3                     },
        {  4, 3, __KERNEL_CS, (unsigned long)overflow                   },
        {  5, 3, __KERNEL_CS, (unsigned long)bounds                     },
        {  6, 0, __KERNEL_CS, (unsigned long)invalid_op                 },
-       {  7, 0, __KERNEL_CS, (unsigned long)device_not_available       },
+       {  7, 0|4, __KERNEL_CS, (unsigned long)device_not_available     },
        {  9, 0, __KERNEL_CS, (unsigned long)coprocessor_segment_overrun },
        { 10, 0, __KERNEL_CS, (unsigned long)invalid_TSS                },
        { 11, 0, __KERNEL_CS, (unsigned long)segment_not_present        },
diff -r dc36edf1102f -r bcccadcc56e5 
linux-2.6-xen-sparse/arch/xen/x86_64/kernel/setup.c
--- a/linux-2.6-xen-sparse/arch/xen/x86_64/kernel/setup.c       Sun Oct 30 
12:52:38 2005
+++ b/linux-2.6-xen-sparse/arch/xen/x86_64/kernel/setup.c       Sun Oct 30 
13:00:35 2005
@@ -733,6 +733,7 @@
 #ifdef CONFIG_XEN
        {
                int i, j, k, fpp;
+               unsigned long va;
 
                /* Make sure we have a large enough P->M table. */
                phys_to_machine_mapping = alloc_bootmem(
@@ -746,9 +747,21 @@
                        __pa(xen_start_info->mfn_list), 
                        PFN_PHYS(PFN_UP(xen_start_info->nr_pages *
                                        sizeof(unsigned long))));
-               make_pages_readonly((void *)xen_start_info->mfn_list,
-                                   PFN_UP(xen_start_info->nr_pages *
-                                          sizeof(unsigned long)));
+
+               /* 'Initial mapping' of old p2m table must be destroyed. */
+               for (va = xen_start_info->mfn_list;
+                    va < (xen_start_info->mfn_list +
+                          (xen_start_info->nr_pages*sizeof(unsigned long)));
+                    va += PAGE_SIZE) {
+                       HYPERVISOR_update_va_mapping(va, __pte_ma(0), 0);
+               }
+
+               /* 'Initial mapping' of initrd must be destroyed. */
+               for (va = xen_start_info->mod_start;
+                    va < (xen_start_info->mod_start+xen_start_info->mod_len);
+                    va += PAGE_SIZE) {
+                       HYPERVISOR_update_va_mapping(va, __pte_ma(0), 0);
+               }
 
                /* 
                 * Initialise the list of the frames that specify the list of 
diff -r dc36edf1102f -r bcccadcc56e5 
linux-2.6-xen-sparse/arch/xen/x86_64/kernel/xen_entry.S
--- a/linux-2.6-xen-sparse/arch/xen/x86_64/kernel/xen_entry.S   Sun Oct 30 
12:52:38 2005
+++ b/linux-2.6-xen-sparse/arch/xen/x86_64/kernel/xen_entry.S   Sun Oct 30 
13:00:35 2005
@@ -5,7 +5,7 @@
 #define evtchn_upcall_pending          0
 #define evtchn_upcall_mask             1
 
-#define sizeof_vcpu_shift              3
+#define sizeof_vcpu_shift              4
 
 #ifdef CONFIG_SMP
 //#define preempt_disable(reg) incl threadinfo_preempt_count(reg)
diff -r dc36edf1102f -r bcccadcc56e5 
linux-2.6-xen-sparse/drivers/xen/balloon/balloon.c
--- a/linux-2.6-xen-sparse/drivers/xen/balloon/balloon.c        Sun Oct 30 
12:52:38 2005
+++ b/linux-2.6-xen-sparse/drivers/xen/balloon/balloon.c        Sun Oct 30 
13:00:35 2005
@@ -191,12 +191,13 @@
        rc = HYPERVISOR_memory_op(
                XENMEM_increase_reservation, &reservation);
        if (rc < nr_pages) {
+               int ret;
                /* We hit the Xen hard limit: reprobe. */
                reservation.extent_start = mfn_list;
                reservation.nr_extents   = rc;
-               BUG_ON(HYPERVISOR_memory_op(
-                       XENMEM_decrease_reservation,
-                       &reservation) != rc);
+               ret = HYPERVISOR_memory_op(XENMEM_decrease_reservation,
+                               &reservation);
+               BUG_ON(ret != rc);
                hard_limit = current_pages + rc - driver_pages;
                goto out;
        }
@@ -213,11 +214,14 @@
                xen_machphys_update(mfn_list[i], pfn);
             
                /* Link back into the page tables if not highmem. */
-               if (pfn < max_low_pfn)
-                       BUG_ON(HYPERVISOR_update_va_mapping(
+               if (pfn < max_low_pfn) {
+                       int ret;
+                       ret = HYPERVISOR_update_va_mapping(
                                (unsigned long)__va(pfn << PAGE_SHIFT),
                                pfn_pte_ma(mfn_list[i], PAGE_KERNEL),
-                               0));
+                               0);
+                       BUG_ON(ret);
+               }
 
                /* Relinquish the page back to the allocator. */
                ClearPageReserved(page);
@@ -242,6 +246,7 @@
        struct page   *page;
        void          *v;
        int            need_sleep = 0;
+       int ret;
        struct xen_memory_reservation reservation = {
                .address_bits = 0,
                .extent_order = 0,
@@ -268,8 +273,9 @@
                if (!PageHighMem(page)) {
                        v = phys_to_virt(pfn << PAGE_SHIFT);
                        scrub_pages(v, 1);
-                       BUG_ON(HYPERVISOR_update_va_mapping(
-                               (unsigned long)v, __pte_ma(0), 0));
+                       ret = HYPERVISOR_update_va_mapping(
+                               (unsigned long)v, __pte_ma(0), 0);
+                       BUG_ON(ret);
                }
 #ifdef CONFIG_XEN_SCRUB_PAGES
                else {
@@ -295,8 +301,8 @@
 
        reservation.extent_start = mfn_list;
        reservation.nr_extents   = nr_pages;
-       BUG_ON(HYPERVISOR_memory_op(
-               XENMEM_decrease_reservation, &reservation) != nr_pages);
+       ret = HYPERVISOR_memory_op(XENMEM_decrease_reservation, &reservation);
+       BUG_ON(ret != nr_pages);
 
        current_pages -= nr_pages;
        totalram_pages = current_pages;
@@ -501,6 +507,7 @@
        pte_t *pte, struct page *pte_page, unsigned long addr, void *data)
 {
        unsigned long mfn = pte_mfn(*pte);
+       int ret;
        struct xen_memory_reservation reservation = {
                .extent_start = &mfn,
                .nr_extents   = 1,
@@ -510,8 +517,8 @@
        set_pte_at(&init_mm, addr, pte, __pte_ma(0));
        phys_to_machine_mapping[__pa(addr) >> PAGE_SHIFT] =
                INVALID_P2M_ENTRY;
-       BUG_ON(HYPERVISOR_memory_op(
-               XENMEM_decrease_reservation, &reservation) != 1);
+       ret = HYPERVISOR_memory_op(XENMEM_decrease_reservation, &reservation);
+       BUG_ON(ret != 1);
        return 0;
 }
 
@@ -519,6 +526,7 @@
 {
        unsigned long vstart, flags;
        unsigned int  order = get_order(nr_pages * PAGE_SIZE);
+       int ret;
 
        vstart = __get_free_pages(GFP_KERNEL, order);
        if (vstart == 0)
@@ -527,8 +535,9 @@
        scrub_pages(vstart, 1 << order);
 
        balloon_lock(flags);
-       BUG_ON(generic_page_range(
-               &init_mm, vstart, PAGE_SIZE << order, dealloc_pte_fn, NULL));
+       ret = generic_page_range(
+               &init_mm, vstart, PAGE_SIZE << order, dealloc_pte_fn, NULL);
+       BUG_ON(ret);
        current_pages -= 1UL << order;
        balloon_unlock(flags);
 
diff -r dc36edf1102f -r bcccadcc56e5 
linux-2.6-xen-sparse/drivers/xen/blkback/blkback.c
--- a/linux-2.6-xen-sparse/drivers/xen/blkback/blkback.c        Sun Oct 30 
12:52:38 2005
+++ b/linux-2.6-xen-sparse/drivers/xen/blkback/blkback.c        Sun Oct 30 
13:00:35 2005
@@ -108,6 +108,7 @@
        struct gnttab_unmap_grant_ref unmap[BLKIF_MAX_SEGMENTS_PER_REQUEST];
        unsigned int i, invcount = 0;
        u16 handle;
+       int ret;
 
        for (i = 0; i < nr_pages; i++) {
                handle = pending_handle(idx, i);
@@ -120,8 +121,9 @@
                invcount++;
        }
 
-       BUG_ON(HYPERVISOR_grant_table_op(
-               GNTTABOP_unmap_grant_ref, unmap, invcount));
+       ret = HYPERVISOR_grant_table_op(
+               GNTTABOP_unmap_grant_ref, unmap, invcount);
+       BUG_ON(ret);
 }
 
 
@@ -338,6 +340,7 @@
        struct bio *bio = NULL, *biolist[BLKIF_MAX_SEGMENTS_PER_REQUEST];
        int nbio = 0;
        request_queue_t *q;
+       int ret;
 
        /* Check that number of segments is sane. */
        nseg = req->nr_segments;
@@ -367,8 +370,8 @@
                        map[i].flags |= GNTMAP_readonly;
        }
 
-       BUG_ON(HYPERVISOR_grant_table_op(
-               GNTTABOP_map_grant_ref, map, nseg));
+       ret = HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, map, nseg);
+       BUG_ON(ret);
 
        for (i = 0; i < nseg; i++) {
                if (unlikely(map[i].handle < 0)) {
@@ -493,6 +496,7 @@
 {
        int i;
        struct page *page;
+       int ret;
 
        blkif_interface_init();
 
@@ -509,7 +513,8 @@
        spin_lock_init(&blkio_schedule_list_lock);
        INIT_LIST_HEAD(&blkio_schedule_list);
 
-       BUG_ON(kernel_thread(blkio_schedule, 0, CLONE_FS | CLONE_FILES) < 0);
+       ret = kernel_thread(blkio_schedule, 0, CLONE_FS | CLONE_FILES);
+       BUG_ON(ret < 0);
 
        blkif_xenbus_init();
 
diff -r dc36edf1102f -r bcccadcc56e5 
linux-2.6-xen-sparse/drivers/xen/blkback/interface.c
--- a/linux-2.6-xen-sparse/drivers/xen/blkback/interface.c      Sun Oct 30 
12:52:38 2005
+++ b/linux-2.6-xen-sparse/drivers/xen/blkback/interface.c      Sun Oct 30 
13:00:35 2005
@@ -31,6 +31,7 @@
 static int map_frontend_page(blkif_t *blkif, unsigned long shared_page)
 {
        struct gnttab_map_grant_ref op;
+       int ret;
 
        op.host_addr = (unsigned long)blkif->blk_ring_area->addr;
        op.flags     = GNTMAP_host_map;
@@ -38,8 +39,9 @@
        op.dom       = blkif->domid;
 
        lock_vm_area(blkif->blk_ring_area);
-       BUG_ON(HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1));
+       ret = HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1);
        unlock_vm_area(blkif->blk_ring_area);
+       BUG_ON(ret);
 
        if (op.handle < 0) {
                DPRINTK(" Grant table operation failure !\n");
@@ -55,14 +57,16 @@
 static void unmap_frontend_page(blkif_t *blkif)
 {
        struct gnttab_unmap_grant_ref op;
+       int ret;
 
        op.host_addr    = (unsigned long)blkif->blk_ring_area->addr;
        op.handle       = blkif->shmem_handle;
        op.dev_bus_addr = 0;
 
        lock_vm_area(blkif->blk_ring_area);
-       BUG_ON(HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1));
+       ret = HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1);
        unlock_vm_area(blkif->blk_ring_area);
+       BUG_ON(ret);
 }
 
 int blkif_map(blkif_t *blkif, unsigned long shared_page, unsigned int evtchn)
diff -r dc36edf1102f -r bcccadcc56e5 
linux-2.6-xen-sparse/drivers/xen/blkfront/blkfront.c
--- a/linux-2.6-xen-sparse/drivers/xen/blkfront/blkfront.c      Sun Oct 30 
12:52:38 2005
+++ b/linux-2.6-xen-sparse/drivers/xen/blkfront/blkfront.c      Sun Oct 30 
13:00:35 2005
@@ -305,6 +305,7 @@
 
        for (i = info->ring.rsp_cons; i != rp; i++) {
                unsigned long id;
+               int ret;
 
                bret = RING_GET_RESPONSE(&info->ring, i);
                id   = bret->id;
@@ -321,9 +322,10 @@
                                DPRINTK("Bad return from blkdev data "
                                        "request: %x\n", bret->status);
 
-                       BUG_ON(end_that_request_first(
+                       ret = end_that_request_first(
                                req, (bret->status == BLKIF_RSP_OKAY),
-                               req->hard_nr_sectors));
+                               req->hard_nr_sectors);
+                       BUG_ON(ret);
                        end_that_request_last(req);
                        break;
                default:
diff -r dc36edf1102f -r bcccadcc56e5 
linux-2.6-xen-sparse/drivers/xen/blktap/blktap.c
--- a/linux-2.6-xen-sparse/drivers/xen/blktap/blktap.c  Sun Oct 30 12:52:38 2005
+++ b/linux-2.6-xen-sparse/drivers/xen/blktap/blktap.c  Sun Oct 30 13:00:35 2005
@@ -413,6 +413,7 @@
        unsigned int i, op = 0;
        struct grant_handle_pair *handle;
        unsigned long ptep;
+       int ret;
 
        for ( i = 0; i < nr_pages; i++)
        {
@@ -440,8 +441,8 @@
                BLKTAP_INVALIDATE_HANDLE(handle);
        }
 
-       BUG_ON(HYPERVISOR_grant_table_op(
-               GNTTABOP_unmap_grant_ref, unmap, op));
+       ret = HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, unmap, op);
+       BUG_ON(ret);
 
        if (blktap_vma != NULL)
                zap_page_range(blktap_vma, 
@@ -673,6 +674,7 @@
        struct gnttab_map_grant_ref map[BLKIF_MAX_SEGMENTS_PER_REQUEST*2];
        int op, ret;
        unsigned int nseg;
+       int retval;
 
        /* Check that number of segments is sane. */
        nseg = req->nr_segments;
@@ -740,8 +742,8 @@
                op++;
        }
 
-       BUG_ON(HYPERVISOR_grant_table_op(
-               GNTTABOP_map_grant_ref, map, op));
+       retval = HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, map, op);
+       BUG_ON(retval);
 
        op = 0;
        for (i = 0; i < (req->nr_segments*2); i += 2) {
@@ -877,7 +879,8 @@
        spin_lock_init(&blkio_schedule_list_lock);
        INIT_LIST_HEAD(&blkio_schedule_list);
 
-       BUG_ON(kernel_thread(blkio_schedule, 0, CLONE_FS | CLONE_FILES) < 0);
+       i = kernel_thread(blkio_schedule, 0, CLONE_FS | CLONE_FILES);
+       BUG_ON(i<0);
 
        blkif_xenbus_init();
 
diff -r dc36edf1102f -r bcccadcc56e5 
linux-2.6-xen-sparse/drivers/xen/blktap/interface.c
--- a/linux-2.6-xen-sparse/drivers/xen/blktap/interface.c       Sun Oct 30 
12:52:38 2005
+++ b/linux-2.6-xen-sparse/drivers/xen/blktap/interface.c       Sun Oct 30 
13:00:35 2005
@@ -31,6 +31,7 @@
 static int map_frontend_page(blkif_t *blkif, unsigned long shared_page)
 {
        struct gnttab_map_grant_ref op;
+       int ret;
 
        op.host_addr = (unsigned long)blkif->blk_ring_area->addr;
        op.flags     = GNTMAP_host_map;
@@ -38,8 +39,9 @@
        op.dom       = blkif->domid;
 
        lock_vm_area(blkif->blk_ring_area);
-       BUG_ON(HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1));
+       ret = HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1);
        unlock_vm_area(blkif->blk_ring_area);
+       BUG_ON(ret);
 
        if (op.handle < 0) {
                DPRINTK(" Grant table operation failure !\n");
@@ -55,14 +57,16 @@
 static void unmap_frontend_page(blkif_t *blkif)
 {
        struct gnttab_unmap_grant_ref op;
+       int ret;
 
        op.host_addr    = (unsigned long)blkif->blk_ring_area->addr;
        op.handle       = blkif->shmem_handle;
        op.dev_bus_addr = 0;
 
        lock_vm_area(blkif->blk_ring_area);
-       BUG_ON(HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1));
+       ret = HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1);
        unlock_vm_area(blkif->blk_ring_area);
+       BUG_ON(ret);
 }
 
 int blkif_map(blkif_t *blkif, unsigned long shared_page, unsigned int evtchn)
diff -r dc36edf1102f -r bcccadcc56e5 
linux-2.6-xen-sparse/drivers/xen/evtchn/evtchn.c
--- a/linux-2.6-xen-sparse/drivers/xen/evtchn/evtchn.c  Sun Oct 30 12:52:38 2005
+++ b/linux-2.6-xen-sparse/drivers/xen/evtchn/evtchn.c  Sun Oct 30 13:00:35 2005
@@ -282,6 +282,7 @@
 
        case IOCTL_EVTCHN_UNBIND: {
                struct ioctl_evtchn_unbind unbind;
+               int ret;
 
                rc = -EFAULT;
                if (copy_from_user(&unbind, (void *)arg, sizeof(unbind)))
@@ -306,7 +307,8 @@
 
                op.cmd = EVTCHNOP_close;
                op.u.close.port = unbind.port;
-               BUG_ON(HYPERVISOR_event_channel_op(&op));
+               ret = HYPERVISOR_event_channel_op(&op);
+               BUG_ON(ret);
 
                rc = 0;
                break;
@@ -399,6 +401,7 @@
 
        for (i = 0; i < NR_EVENT_CHANNELS; i++)
        {
+               int ret;
                if (port_user[i] != u)
                        continue;
 
@@ -407,7 +410,8 @@
 
                op.cmd = EVTCHNOP_close;
                op.u.close.port = i;
-               BUG_ON(HYPERVISOR_event_channel_op(&op));
+               ret = HYPERVISOR_event_channel_op(&op);
+               BUG_ON(ret);
        }
 
        spin_unlock_irq(&port_user_lock);
diff -r dc36edf1102f -r bcccadcc56e5 
linux-2.6-xen-sparse/drivers/xen/netback/interface.c
--- a/linux-2.6-xen-sparse/drivers/xen/netback/interface.c      Sun Oct 30 
12:52:38 2005
+++ b/linux-2.6-xen-sparse/drivers/xen/netback/interface.c      Sun Oct 30 
13:00:35 2005
@@ -115,6 +115,7 @@
        netif_t *netif, grant_ref_t tx_ring_ref, grant_ref_t rx_ring_ref)
 {
        struct gnttab_map_grant_ref op;
+       int ret;
 
        op.host_addr = (unsigned long)netif->comms_area->addr;
        op.flags     = GNTMAP_host_map;
@@ -122,8 +123,9 @@
        op.dom       = netif->domid;
     
        lock_vm_area(netif->comms_area);
-       BUG_ON(HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1));
+       ret = HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1);
        unlock_vm_area(netif->comms_area);
+       BUG_ON(ret);
 
        if (op.handle < 0) { 
                DPRINTK(" Gnttab failure mapping tx_ring_ref!\n");
@@ -139,8 +141,9 @@
        op.dom       = netif->domid;
 
        lock_vm_area(netif->comms_area);
-       BUG_ON(HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1));
+       ret = HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1);
        unlock_vm_area(netif->comms_area);
+       BUG_ON(ret);
 
        if (op.handle < 0) { 
                DPRINTK(" Gnttab failure mapping rx_ring_ref!\n");
@@ -156,22 +159,25 @@
 static void unmap_frontend_pages(netif_t *netif)
 {
        struct gnttab_unmap_grant_ref op;
+       int ret;
 
        op.host_addr    = (unsigned long)netif->comms_area->addr;
        op.handle       = netif->tx_shmem_handle;
        op.dev_bus_addr = 0;
 
        lock_vm_area(netif->comms_area);
-       BUG_ON(HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1));
+       ret = HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1);
        unlock_vm_area(netif->comms_area);
+       BUG_ON(ret);
 
        op.host_addr    = (unsigned long)netif->comms_area->addr + PAGE_SIZE;
        op.handle       = netif->rx_shmem_handle;
        op.dev_bus_addr = 0;
 
        lock_vm_area(netif->comms_area);
-       BUG_ON(HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1));
+       ret = HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1);
        unlock_vm_area(netif->comms_area);
+       BUG_ON(ret);
 }
 
 int netif_map(netif_t *netif, unsigned long tx_ring_ref,
diff -r dc36edf1102f -r bcccadcc56e5 
linux-2.6-xen-sparse/drivers/xen/netback/netback.c
--- a/linux-2.6-xen-sparse/drivers/xen/netback/netback.c        Sun Oct 30 
12:52:38 2005
+++ b/linux-2.6-xen-sparse/drivers/xen/netback/netback.c        Sun Oct 30 
13:00:35 2005
@@ -112,9 +112,12 @@
        spin_lock_irqsave(&mfn_lock, flags);
        if ( alloc_index != MAX_MFN_ALLOC )
                mfn_list[alloc_index++] = mfn;
-       else
-               BUG_ON(HYPERVISOR_memory_op(XENMEM_decrease_reservation,
-                                           &reservation) != 1);
+       else {
+               int ret;
+               ret = HYPERVISOR_memory_op(XENMEM_decrease_reservation,
+                                           &reservation);
+               BUG_ON(ret != 1);
+       }
        spin_unlock_irqrestore(&mfn_lock, flags);
 }
 #endif
@@ -159,13 +162,15 @@
         */
        if (skb_shared(skb) || skb_cloned(skb) || !is_xen_skb(skb)) {
                int hlen = skb->data - skb->head;
+               int ret;
                struct sk_buff *nskb = dev_alloc_skb(hlen + skb->len);
                if ( unlikely(nskb == NULL) )
                        goto drop;
                skb_reserve(nskb, hlen);
                __skb_put(nskb, skb->len);
-               BUG_ON(skb_copy_bits(skb, -hlen, nskb->data - hlen,
-                                    skb->len + hlen));
+               ret = skb_copy_bits(skb, -hlen, nskb->data - hlen,
+                                    skb->len + hlen);
+               BUG_ON(ret);
                nskb->dev = skb->dev;
                nskb->proto_csum_valid = skb->proto_csum_valid;
                dev_kfree_skb(skb);
@@ -218,6 +223,7 @@
        struct sk_buff *skb;
        u16 notify_list[NETIF_RX_RING_SIZE];
        int notify_nr = 0;
+       int ret;
 
        skb_queue_head_init(&rxq);
 
@@ -279,7 +285,8 @@
        mcl++;
 
        mcl[-2].args[MULTI_UVMFLAGS_INDEX] = UVMF_TLB_FLUSH|UVMF_ALL;
-       BUG_ON(HYPERVISOR_multicall(rx_mcl, mcl - rx_mcl) != 0);
+       ret = HYPERVISOR_multicall(rx_mcl, mcl - rx_mcl);
+       BUG_ON(ret != 0);
 
        mcl = rx_mcl;
        if( HYPERVISOR_grant_table_op(GNTTABOP_transfer, grant_rx_op, 
@@ -421,6 +428,7 @@
        u16 pending_idx;
        PEND_RING_IDX dc, dp;
        netif_t *netif;
+       int ret;
 
        dc = dealloc_cons;
        dp = dealloc_prod;
@@ -436,8 +444,9 @@
                gop->handle       = grant_tx_ref[pending_idx];
                gop++;
        }
-       BUG_ON(HYPERVISOR_grant_table_op(
-               GNTTABOP_unmap_grant_ref, tx_unmap_ops, gop - tx_unmap_ops));
+       ret = HYPERVISOR_grant_table_op(
+               GNTTABOP_unmap_grant_ref, tx_unmap_ops, gop - tx_unmap_ops);
+       BUG_ON(ret);
 
        while (dealloc_cons != dp) {
                pending_idx = dealloc_ring[MASK_PEND_IDX(dealloc_cons++)];
@@ -477,6 +486,7 @@
        NETIF_RING_IDX i;
        gnttab_map_grant_ref_t *mop;
        unsigned int data_len;
+       int ret;
 
        if (dealloc_cons != dealloc_prod)
                net_tx_action_dealloc();
@@ -599,8 +609,9 @@
        if (mop == tx_map_ops)
                return;
 
-       BUG_ON(HYPERVISOR_grant_table_op(
-               GNTTABOP_map_grant_ref, tx_map_ops, mop - tx_map_ops));
+       ret = HYPERVISOR_grant_table_op(
+               GNTTABOP_map_grant_ref, tx_map_ops, mop - tx_map_ops);
+       BUG_ON(ret);
 
        mop = tx_map_ops;
        while ((skb = __skb_dequeue(&tx_queue)) != NULL) {
diff -r dc36edf1102f -r bcccadcc56e5 
linux-2.6-xen-sparse/drivers/xen/privcmd/privcmd.c
--- a/linux-2.6-xen-sparse/drivers/xen/privcmd/privcmd.c        Sun Oct 30 
12:52:38 2005
+++ b/linux-2.6-xen-sparse/drivers/xen/privcmd/privcmd.c        Sun Oct 30 
13:00:35 2005
@@ -25,8 +25,8 @@
 #include <asm/pgtable.h>
 #include <asm/uaccess.h>
 #include <asm/tlb.h>
+#include <asm/hypervisor.h>
 #include <asm-xen/linux-public/privcmd.h>
-#include <asm/hypervisor.h>
 #include <asm-xen/xen-public/xen.h>
 #include <asm-xen/xen-public/dom0_ops.h>
 #include <asm-xen/xen_proc.h>
diff -r dc36edf1102f -r bcccadcc56e5 
linux-2.6-xen-sparse/drivers/xen/tpmback/interface.c
--- a/linux-2.6-xen-sparse/drivers/xen/tpmback/interface.c      Sun Oct 30 
12:52:38 2005
+++ b/linux-2.6-xen-sparse/drivers/xen/tpmback/interface.c      Sun Oct 30 
13:00:35 2005
@@ -78,6 +78,7 @@
 static int
 map_frontend_page(tpmif_t *tpmif, unsigned long shared_page)
 {
+       int ret;
        struct gnttab_map_grant_ref op = {
                .host_addr = (unsigned long)tpmif->tx_area->addr,
                .flags = GNTMAP_host_map,
@@ -86,8 +87,9 @@
        };
 
        lock_vm_area(tpmif->tx_area);
-       BUG_ON(HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1));
+       ret = HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1);
        unlock_vm_area(tpmif->tx_area);
+       BUG_ON(ret);
 
        if (op.handle < 0) {
                DPRINTK(" Grant table operation failure !\n");
@@ -104,14 +106,16 @@
 unmap_frontend_page(tpmif_t *tpmif)
 {
        struct gnttab_unmap_grant_ref op;
+       int ret;
 
        op.host_addr    = (unsigned long)tpmif->tx_area->addr;
        op.handle       = tpmif->shmem_handle;
        op.dev_bus_addr = 0;
 
        lock_vm_area(tpmif->tx_area);
-       BUG_ON(HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1));
+       ret = HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1);
        unlock_vm_area(tpmif->tx_area);
+       BUG_ON(ret);
 }
 
 int
diff -r dc36edf1102f -r bcccadcc56e5 linux-2.6-xen-sparse/drivers/xen/util.c
--- a/linux-2.6-xen-sparse/drivers/xen/util.c   Sun Oct 30 12:52:38 2005
+++ b/linux-2.6-xen-sparse/drivers/xen/util.c   Sun Oct 30 13:00:35 2005
@@ -34,7 +34,9 @@
 
 void free_vm_area(struct vm_struct *area)
 {
-       BUG_ON(remove_vm_area(area->addr) != area);
+       struct vm_struct *ret;
+       ret = remove_vm_area(area->addr);
+       BUG_ON(ret != area);
        kfree(area);
 }
 
diff -r dc36edf1102f -r bcccadcc56e5 
linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c
--- a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c    Sun Oct 30 
12:52:38 2005
+++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c    Sun Oct 30 
13:00:35 2005
@@ -714,11 +714,7 @@
 
 static int __init xenbus_probe_init(void)
 {
-       int err = 0;
-       /* 
-       ** Domain0 doesn't have a store_evtchn or store_mfn yet. 
-       */
-       int dom0 = (xen_start_info->store_evtchn == 0);
+       int err = 0, dom0;
 
        printk("xenbus_probe_init\n");
 
@@ -733,10 +729,16 @@
        device_register(&xenbus_frontend.dev);
        device_register(&xenbus_backend.dev);
 
+       /*
+       ** Domain0 doesn't have a store_evtchn or store_mfn yet.
+       */
+       dom0 = (xen_start_info->store_evtchn == 0);
+
        if (dom0) {
 
                unsigned long page;
                evtchn_op_t op = { 0 };
+               int ret;
 
 
                /* Allocate page. */
@@ -757,7 +759,8 @@
                op.u.alloc_unbound.dom        = DOMID_SELF;
                op.u.alloc_unbound.remote_dom = 0; 
 
-               BUG_ON(HYPERVISOR_event_channel_op(&op)); 
+               ret = HYPERVISOR_event_channel_op(&op);
+               BUG_ON(ret); 
                xen_start_info->store_evtchn = op.u.alloc_unbound.port;
 
                /* And finally publish the above info in /proc/xen */
diff -r dc36edf1102f -r bcccadcc56e5 
linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_xs.c
--- a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_xs.c       Sun Oct 30 
12:52:38 2005
+++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_xs.c       Sun Oct 30 
13:00:35 2005
@@ -28,6 +28,7 @@
  * IN THE SOFTWARE.
  */
 
+#include <linux/unistd.h>
 #include <linux/errno.h>
 #include <linux/types.h>
 #include <linux/uio.h>
diff -r dc36edf1102f -r bcccadcc56e5 tools/examples/Makefile
--- a/tools/examples/Makefile   Sun Oct 30 12:52:38 2005
+++ b/tools/examples/Makefile   Sun Oct 30 13:00:35 2005
@@ -17,6 +17,7 @@
 XEN_CONFIGS += xmexample1 
 XEN_CONFIGS += xmexample2
 XEN_CONFIGS += xmexample.vmx
+XEN_CONFIGS += xmexample.vti
 
 # Xen script dir and scripts to go there.
 XEN_SCRIPT_DIR = /etc/xen/scripts
diff -r dc36edf1102f -r bcccadcc56e5 tools/ioemu/hw/ide.c
--- a/tools/ioemu/hw/ide.c      Sun Oct 30 12:52:38 2005
+++ b/tools/ioemu/hw/ide.c      Sun Oct 30 13:00:35 2005
@@ -22,6 +22,7 @@
  * THE SOFTWARE.
  */
 #include "vl.h"
+#include <pthread.h>
 
 /* debug IDE devices */
 //#define DEBUG_IDE
@@ -359,6 +360,48 @@
     IDEState ide_if[4];
     BMDMAState bmdma[2];
 } PCIIDEState;
+
+#define DMA_MULTI_THREAD
+
+#ifdef DMA_MULTI_THREAD
+
+static int file_pipes[2];
+
+static void ide_dma_loop(BMDMAState *bm);
+static void dma_thread_loop(BMDMAState *bm);
+
+static void *dma_thread_func(void* opaque)
+{
+    BMDMAState* req;
+
+    while (read(file_pipes[0], &req, sizeof(req))) {
+        dma_thread_loop(req);
+    }
+
+    return NULL;
+}
+
+static void dma_create_thread()
+{
+    pthread_t tid;
+    int rt;
+
+    if (pipe(file_pipes) != 0){
+        fprintf(stderr, "create pipe failed\n");
+        exit(1);
+    }
+
+    if ( (rt = pthread_create(&tid, NULL, dma_thread_func, NULL)) ) {
+        fprintf(stderr, "Oops, dma thread creation failed, errno=%d\n", rt);
+        exit(1);
+    }
+
+    if ( (rt = pthread_detach(tid)) ) {
+        fprintf(stderr, "Oops, dma thread detachment failed, errno=%d\n", rt);
+        exit(1);
+    }
+}
+#endif //DMA_MULTI_THREAD
 
 static void ide_dma_start(IDEState *s, IDEDMAFunc *dma_cb);
 
@@ -1978,7 +2021,15 @@
 
 /* XXX: full callback usage to prepare non blocking I/Os support -
    error handling */
+#ifdef DMA_MULTI_THREAD
 static void ide_dma_loop(BMDMAState *bm)
+{
+    write(file_pipes[1], &bm, sizeof(bm));
+}
+static void dma_thread_loop(BMDMAState *bm)
+#else 
+static void ide_dma_loop(BMDMAState *bm)
+#endif //DMA_MULTI_THREAD
 {
     struct {
         uint32_t addr;
@@ -2166,6 +2217,9 @@
         d->ide_if[i].pci_dev = (PCIDevice *)d;
     ide_init2(&d->ide_if[0], 16, hd_table[0], hd_table[1]);
     ide_init2(&d->ide_if[2], 16, hd_table[2], hd_table[3]);
+#ifdef DMA_MULTI_THREAD    
+    dma_create_thread();
+#endif //DMA_MULTI_THREAD    
 }
 
 /* hd_table must contain 4 block drivers */
@@ -2196,6 +2250,9 @@
     ide_init2(&d->ide_if[2], 15, hd_table[2], hd_table[3]);
     ide_init_ioport(&d->ide_if[0], 0x1f0, 0x3f6);
     ide_init_ioport(&d->ide_if[2], 0x170, 0x376);
+#ifdef DMA_MULTI_THREAD    
+    dma_create_thread();
+#endif //DMA_MULTI_THREAD    
 }
 
 /***********************************************************/
diff -r dc36edf1102f -r bcccadcc56e5 tools/libxc/xc_elf.h
--- a/tools/libxc/xc_elf.h      Sun Oct 30 12:52:38 2005
+++ b/tools/libxc/xc_elf.h      Sun Oct 30 13:00:35 2005
@@ -24,26 +24,26 @@
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-typedef u_int8_t       Elf_Byte;
-
-typedef u_int32_t      Elf32_Addr;     /* Unsigned program address */
-typedef u_int32_t      Elf32_Off;      /* Unsigned file offset */
+typedef uint8_t                Elf_Byte;
+
+typedef uint32_t       Elf32_Addr;     /* Unsigned program address */
+typedef uint32_t       Elf32_Off;      /* Unsigned file offset */
 typedef int32_t                Elf32_Sword;    /* Signed large integer */
-typedef u_int32_t      Elf32_Word;     /* Unsigned large integer */
-typedef u_int16_t      Elf32_Half;     /* Unsigned medium integer */
-
-typedef u_int64_t      Elf64_Addr;
-typedef u_int64_t      Elf64_Off;
+typedef uint32_t       Elf32_Word;     /* Unsigned large integer */
+typedef uint16_t       Elf32_Half;     /* Unsigned medium integer */
+
+typedef uint64_t       Elf64_Addr;
+typedef uint64_t       Elf64_Off;
 typedef int32_t                Elf64_Shalf;
 
 typedef int32_t                Elf64_Sword;
-typedef u_int32_t      Elf64_Word;
+typedef uint32_t       Elf64_Word;
 
 typedef int64_t                Elf64_Sxword;
-typedef u_int64_t      Elf64_Xword;
-
-typedef u_int32_t      Elf64_Half;
-typedef u_int16_t      Elf64_Quarter;
+typedef uint64_t       Elf64_Xword;
+
+typedef uint32_t       Elf64_Half;
+typedef uint16_t       Elf64_Quarter;
 
 /*
  * e_ident[] identification indexes 
diff -r dc36edf1102f -r bcccadcc56e5 tools/libxc/xc_ia64_stubs.c
--- a/tools/libxc/xc_ia64_stubs.c       Sun Oct 30 12:52:38 2005
+++ b/tools/libxc/xc_ia64_stubs.c       Sun Oct 30 13:00:35 2005
@@ -1,5 +1,11 @@
 #include "xg_private.h"
 #include "xenguest.h"
+#include "xc_private.h"
+#include "xc_elf.h"
+#include <stdlib.h>
+#include <zlib.h>
+#include "xen/arch-ia64.h"
+#include <xen/io/ioreq.h>
 
 int xc_linux_save(int xc_handle, int io_fd, uint32_t dom, uint32_t max_iters, 
                   uint32_t max_factor, uint32_t flags)
@@ -13,22 +19,6 @@
                      unsigned int console_evtchn, unsigned long *console_mfn)
 {
     PERROR("xc_linux_restore not implemented\n");
-    return -1;
-}
-
-int xc_vmx_build(int xc_handle,
-                   uint32_t domid,
-                   int memsize,
-                   const char *image_name,
-                   struct mem_map *mem_mapp,
-                   const char *ramdisk_name,
-                   const char *cmdline,
-                   unsigned int control_evtchn,
-                   unsigned int vcpus,
-                   unsigned int store_evtchn,
-                   unsigned long *store_mfn)
-{
-    PERROR("xc_vmx_build not implemented\n");
     return -1;
 }
 
@@ -40,6 +30,653 @@
                unsigned int control_evtchn, unsigned long flags)
 {
     PERROR("xc_plan9_build not implemented\n");
+    return -1;
+}
+
+int xc_ia64_get_pfn_list(int xc_handle,
+                         uint32_t domid, 
+                         unsigned long *pfn_buf, 
+                         unsigned int start_page,
+                         unsigned int nr_pages)
+{
+    dom0_op_t op;
+    int ret;
+    unsigned long max_pfns = ((unsigned long)start_page << 32) | nr_pages;
+
+    op.cmd = DOM0_GETMEMLIST;
+    op.u.getmemlist.domain   = (domid_t)domid;
+    op.u.getmemlist.max_pfns = max_pfns;
+    op.u.getmemlist.buffer   = pfn_buf;
+
+    if ( (max_pfns != -1UL)
+               && mlock(pfn_buf, nr_pages * sizeof(unsigned long)) != 0 )
+    {
+        PERROR("Could not lock pfn list buffer");
+        return -1;
+    }    
+
+    ret = do_dom0_op(xc_handle, &op);
+
+    if (max_pfns != -1UL)
+       (void)munlock(pfn_buf, nr_pages * sizeof(unsigned long));
+
+    return (ret < 0) ? -1 : op.u.getmemlist.num_pfns;
+}
+
+long xc_get_max_pages(int xc_handle, uint32_t domid)
+{
+    dom0_op_t op;
+    op.cmd = DOM0_GETDOMAININFO;
+    op.u.getdomaininfo.domain = (domid_t)domid;
+    return (do_dom0_op(xc_handle, &op) < 0) ? 
+        -1 : op.u.getdomaininfo.max_pages;
+}
+
+int xc_ia64_copy_to_domain_pages(int xc_handle, uint32_t domid,
+        void* src_page, unsigned long dst_pfn, int nr_pages)
+{
+    // N.B. gva should be page aligned
+    
+    unsigned long *page_array=NULL;
+    int i;
+
+    if ( (page_array = malloc(nr_pages * sizeof(unsigned long))) == NULL ){
+        PERROR("Could not allocate memory");
+        goto error_out;
+    }
+    if ( xc_ia64_get_pfn_list(xc_handle, domid, page_array,
+                dst_pfn>>PAGE_SHIFT, nr_pages) != nr_pages ){
+        PERROR("Could not get the page frame list");
+        goto error_out;
+    }
+
+    for ( i=0; i< nr_pages; i++ ){
+       if (xc_copy_to_domain_page(xc_handle, domid, page_array[i],
+                       src_page + (i << PAGE_SHIFT)))
+           goto error_out;
+    }
+    free(page_array);
+    return 0;
+    
+error_out:
+    if (page_array)
+        free(page_array);
+    return -1;
+}
+
+
+#define HOB_SIGNATURE 0x3436474953424f48 // "HOBSIG64"
+#define GFW_HOB_START    ((4UL<<30)-(14UL<<20))    //4G -14M
+#define GFW_HOB_SIZE     (1UL<<20)              //1M
+#define MEM_G   (1UL << 30) 
+#define MEM_M   (1UL << 20) 
+
+typedef struct {
+    unsigned long signature;
+    unsigned int  type;
+    unsigned int  length;
+} HOB_GENERIC_HEADER;
+
+/*
+ * INFO HOB is the first data data in one HOB list
+ * it contains the control information of the HOB list
+ */
+typedef struct { 
+    HOB_GENERIC_HEADER  header;
+    unsigned long       length;    // current length of hob
+    unsigned long       cur_pos;   // current poisiton of hob
+    unsigned long       buf_size;  // size of hob buffer
+}HOB_INFO;
+
+typedef struct{
+    unsigned long start;
+    unsigned long size;
+}hob_mem_t;
+
+typedef enum {
+    HOB_TYPE_INFO=0,
+    HOB_TYPE_TERMINAL,
+    HOB_TYPE_MEM,
+    HOB_TYPE_PAL_BUS_GET_FEATURES_DATA,
+    HOB_TYPE_PAL_CACHE_SUMMARY,
+    HOB_TYPE_PAL_MEM_ATTRIB,
+    HOB_TYPE_PAL_CACHE_INFO,
+    HOB_TYPE_PAL_CACHE_PROT_INFO,
+    HOB_TYPE_PAL_DEBUG_INFO,
+    HOB_TYPE_PAL_FIXED_ADDR,
+    HOB_TYPE_PAL_FREQ_BASE,
+    HOB_TYPE_PAL_FREQ_RATIOS,
+    HOB_TYPE_PAL_HALT_INFO,
+    HOB_TYPE_PAL_PERF_MON_INFO,
+    HOB_TYPE_PAL_PROC_GET_FEATURES,
+    HOB_TYPE_PAL_PTCE_INFO,
+    HOB_TYPE_PAL_REGISTER_INFO,
+    HOB_TYPE_PAL_RSE_INFO,
+    HOB_TYPE_PAL_TEST_INFO,
+    HOB_TYPE_PAL_VM_SUMMARY,
+    HOB_TYPE_PAL_VM_INFO,
+    HOB_TYPE_PAL_VM_PAGE_SIZE,
+    HOB_TYPE_MAX
+}hob_type_t;
+
+static int hob_init( void  *buffer ,unsigned long buf_size);
+static int add_pal_hob(void* hob_buf);
+static int add_mem_hob(void* hob_buf, unsigned long dom_mem_size);
+static int build_hob (void* hob_buf, unsigned long hob_buf_size,
+                  unsigned long dom_mem_size);
+static int load_hob(int xc_handle,uint32_t dom, void *hob_buf);
+
+int xc_ia64_build_hob(int xc_handle, uint32_t dom, unsigned long memsize){
+
+    char   hob_buf[GFW_HOB_SIZE];
+
+    if ( build_hob( hob_buf, GFW_HOB_SIZE, memsize<<20) < 0){
+        PERROR("Could not build hob");
+        return -1;
+    }
+
+    if ( load_hob( xc_handle, dom, hob_buf) <0){
+        PERROR("Could not load hob");
+       return -1;
+    }
+
+    return 0;
+
+}
+static int
+hob_init( void  *buffer ,unsigned long buf_size)
+{
+    HOB_INFO *phit;
+    HOB_GENERIC_HEADER     *terminal;
+
+    if (sizeof(HOB_INFO) + sizeof(HOB_GENERIC_HEADER) > buf_size){
+        // buffer too small
+        return -1;
+    }
+    
+    phit = (HOB_INFO*)buffer;
+    phit->header.signature = HOB_SIGNATURE;
+    phit->header.type = HOB_TYPE_INFO;
+    phit->header.length = sizeof(HOB_INFO);
+    phit->length = sizeof(HOB_INFO) + sizeof(HOB_GENERIC_HEADER);
+    phit->cur_pos = 0;
+    phit->buf_size = buf_size;
+    
+    terminal = (HOB_GENERIC_HEADER*) (buffer + sizeof(HOB_INFO));
+    terminal->signature= HOB_SIGNATURE;
+    terminal->type = HOB_TYPE_TERMINAL;
+    terminal->length = sizeof(HOB_GENERIC_HEADER);
+
+    return 0;
+}
+
+/*
+ *  Add a new HOB to the HOB List.
+ *       
+ *  hob_start  -  start address of hob buffer
+ *  type       -  type of the hob to be added
+ *  data       -  data of the hob to be added
+ *  data_size  -  size of the data
+ */
+static int
+hob_add(
+     void*  hob_start,
+     int    type,
+     void*  data,
+     int    data_size
+)
+{
+    HOB_INFO *phit;
+    HOB_GENERIC_HEADER     *newhob,*tail;   
+    
+    phit = (HOB_INFO*)hob_start;
+
+    if (phit->length + data_size > phit->buf_size){
+        // no space for new hob
+        return -1;
+    }
+
+    //append new HOB 
+    newhob = (HOB_GENERIC_HEADER*)
+        (hob_start + phit->length - sizeof(HOB_GENERIC_HEADER));
+    newhob->signature = HOB_SIGNATURE;
+    newhob->type = type;
+    newhob->length = data_size + sizeof(HOB_GENERIC_HEADER);
+    memcpy((void*)newhob + sizeof(HOB_GENERIC_HEADER), data, data_size);
+
+    // append terminal HOB  
+    tail = (HOB_GENERIC_HEADER*) ( hob_start + phit->length + data_size);
+    tail->signature = HOB_SIGNATURE;
+    tail->type = HOB_TYPE_TERMINAL;
+    tail->length = sizeof(HOB_GENERIC_HEADER);
+
+    // adjust HOB list length
+    phit->length += sizeof(HOB_GENERIC_HEADER)+ data_size;
+
+    return 0;
+
+}
+
+int get_hob_size(void* hob_buf){
+    
+    HOB_INFO *phit = (HOB_INFO*)hob_buf;
+    
+    if (phit->header.signature != HOB_SIGNATURE){
+        PERROR("xc_get_hob_size:Incorrect signature");
+        return -1;
+    }
+    return phit->length;
+}
+
+int build_hob (void* hob_buf, unsigned long hob_buf_size,
+                  unsigned long dom_mem_size)
+{   
+    //Init HOB List 
+    if (hob_init (hob_buf, hob_buf_size)<0){
+        PERROR("buffer too small");
+        goto err_out;
+    }
+    
+    if ( add_mem_hob( hob_buf,dom_mem_size) < 0){
+        PERROR("Add memory hob failed, buffer too small");
+        goto err_out;
+    }
+    
+    if ( add_pal_hob( hob_buf ) < 0 ){
+        PERROR("Add PAL hob failed, buffer too small");
+        goto err_out;
+    }
+    
+    return 0;
+
+err_out:
+    return -1;  
+}
+
+static int 
+load_hob(int xc_handle, uint32_t dom, void *hob_buf)
+{
+    // hob_buf should be page aligned
+    int hob_size;
+    int nr_pages;
+
+    if ((hob_size = get_hob_size(hob_buf)) < 0){
+        PERROR("Invalid hob data");
+        return -1;
+    }
+
+    if (hob_size > GFW_HOB_SIZE){
+        PERROR("No enough memory for hob data");
+        return -1;
+    }
+
+    nr_pages = (hob_size + PAGE_SIZE -1) >> PAGE_SHIFT;
+    
+    return xc_ia64_copy_to_domain_pages(xc_handle, dom,
+            hob_buf, GFW_HOB_START, nr_pages );
+}
+
+#define MIN(x, y) ((x) < (y)) ? (x) : (y)
+static int 
+add_mem_hob(void* hob_buf, unsigned long dom_mem_size){
+    hob_mem_t memhob;
+
+    // less than 3G
+    memhob.start = 0;
+    memhob.size = MIN(dom_mem_size, 0xC0000000);
+    
+    if (hob_add(hob_buf, HOB_TYPE_MEM, &memhob, sizeof(memhob)) < 0){
+       return -1;
+    }
+
+    if (dom_mem_size > 0xC0000000) {
+        // 4G ~ 4G+remain
+        memhob.start = 0x100000000; //4G
+        memhob.size = dom_mem_size - 0xC0000000;
+        if (hob_add(hob_buf, HOB_TYPE_MEM, &memhob, sizeof(memhob)) < 0)
+            return -1;
+    }
+    return 0;
+}
+
+unsigned char config_pal_bus_get_features_data[24] = {
+    0, 0, 0, 32, 0, 0, 240, 189, 0, 0, 0, 0, 0, 0,
+    0, 0, 0, 0, 0, 0, 0, 0, 0, 0
+};
+unsigned char config_pal_cache_summary[16] = {
+    3, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0};
+unsigned char config_pal_mem_attrib[8] =    {
+    241, 0, 0, 0, 0, 0, 0, 0
+};
+unsigned char config_pal_cache_info[152] = {
+    3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+    6, 4, 6, 7, 255, 1, 0, 1, 0, 64, 0, 0, 12, 12, 
+    49, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 6, 7, 0, 1,
+    0, 1, 0, 64, 0, 0, 12, 12, 49, 0, 0, 0, 0, 0, 0, 
+    0, 0, 0, 6, 8, 7, 7, 255, 7, 0, 11, 0, 0, 16, 0, 
+    12, 17, 49, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 8, 7, 
+    7, 7, 5, 9, 11, 0, 0, 4, 0, 12, 15, 49, 0, 254, 255,
+    255, 255, 255, 255, 255, 255, 2, 8, 7, 7, 7, 5, 9, 
+    11, 0, 0, 4, 0, 12, 15, 49, 0, 0, 0, 0, 0, 0, 0, 0, 
+    0, 3, 12, 7, 7, 7, 14, 1, 3, 0, 0, 192, 0, 12, 20, 49, 0
+};
+unsigned char config_pal_cache_prot_info[200] = {
+    3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
+    45, 0, 16, 8, 0, 76, 12, 64, 0, 0, 0, 0, 0, 0, 0,
+    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
+    8, 0, 16, 4, 0, 76, 44, 68, 0, 0, 0, 0, 0, 0, 0, 0, 
+    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 32, 
+    0, 16, 8, 0, 81, 44, 72, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
+    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 32, 0,
+    112, 12, 0, 79, 124, 76, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
+    0, 0, 0, 0, 0, 0, 254, 255, 255, 255, 255, 255, 255, 255, 
+    32, 0, 112, 12, 0, 79, 124, 76, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 0, 160, 
+    12, 0, 84, 124, 76, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
+    0, 0, 0
+};
+unsigned char config_pal_debug_info[16] = {
+    2, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0
+};
+unsigned char config_pal_fixed_addr[8] = {
+    0, 0, 0, 0, 0, 0, 0, 0
+};
+unsigned char config_pal_freq_base[8] = {
+    109, 219, 182, 13, 0, 0, 0, 0
+};
+unsigned char config_pal_freq_ratios[24] = {
+    11, 1, 0, 0, 77, 7, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 4, 
+    0, 0, 0, 7, 0, 0, 0
+};
+unsigned char config_pal_halt_info[64] = {
+    0, 0, 0, 0, 0, 0, 0, 48, 0, 0, 0, 0, 0, 0, 0, 0, 
+    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
+    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
+};
+unsigned char config_pal_perf_mon_info[136] = {
+    12, 47, 18, 8, 0, 0, 0, 0, 241, 255, 0, 0, 255, 7, 0, 0, 
+    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
+    0, 0, 0, 0, 0, 0, 0, 0, 241, 255, 0, 0, 223, 0, 255, 255, 
+    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
+    0, 0, 0, 0, 0, 0, 0, 0, 240, 255, 0, 0, 0, 0, 0, 0, 
+    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
+    0, 0, 0, 0, 0, 0, 0, 0, 240, 255, 0, 0, 0, 0, 0, 0, 
+    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
+    0, 0, 0, 0, 0, 0, 0, 0
+};
+unsigned char config_pal_proc_get_features[104] = {
+    3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
+    0, 0, 0, 0, 64, 6, 64, 49, 0, 0, 0, 0, 64, 6, 0, 0, 
+    0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 0, 0, 0, 0, 0, 0, 
+    231, 0, 0, 0, 0, 0, 0, 0, 228, 0, 0, 0, 0, 0, 0, 0, 
+    0, 0, 0, 0, 0, 0, 0, 0, 17, 0, 0, 0, 0, 0, 0, 0, 
+    63, 0, 0, 0, 0, 0, 0, 0, 32, 0, 0, 0, 0, 0, 0, 0,
+    0, 0, 0, 0, 0, 0, 0, 0
+};
+unsigned char config_pal_ptce_info[24] = {
+    0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 
+    0, 0, 0, 0, 0, 0, 0, 0
+};
+unsigned char config_pal_register_info[64] = {
+    255, 0, 47, 127, 17, 17, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0, 0,
+    255, 208, 128, 238, 238, 0, 0, 248, 255, 255, 255, 255, 255, 0, 0, 7, 3,
+    251, 3, 0, 0, 0, 0, 255, 7, 3, 0, 0, 0, 0, 0, 248, 252, 4,
+    252, 255, 255, 255, 255, 2, 248, 252, 255, 255, 255, 255, 255
+};
+unsigned char config_pal_rse_info[16] = {
+    96, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
+};
+unsigned char config_pal_test_info[48] = {
+    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
+};
+unsigned char config_pal_vm_summary[16] = {
+    101, 18, 15, 2, 7, 7, 4, 2, 59, 18, 0, 0, 0, 0, 0, 0
+};
+unsigned char config_pal_vm_info[104] = {
+    2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
+    32, 32, 0, 0, 0, 0, 0, 0, 112, 85, 21, 0, 0, 0, 0, 0, 0,
+    0, 0, 0, 0, 0, 0, 1, 32, 32, 0, 0, 0, 0, 0, 0, 112, 85,
+    21, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 128, 128, 0,
+    4, 0, 0, 0, 0, 112, 85, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+    0, 0, 0, 1, 128, 128, 0, 4, 0, 0, 0, 0, 112, 85, 0, 0, 0, 0, 0
+};
+unsigned char config_pal_vm_page_size[16] = {
+    0, 112, 85, 21, 0, 0, 0, 0, 0, 112, 85, 21, 0, 0, 0, 0
+};
+
+typedef struct{
+    hob_type_t type;
+    void* data;
+    unsigned long size;     
+}hob_batch_t;
+
+hob_batch_t hob_batch[]={
+    {  HOB_TYPE_PAL_BUS_GET_FEATURES_DATA,
+        &config_pal_bus_get_features_data,
+        sizeof(config_pal_bus_get_features_data)
+    },
+    {  HOB_TYPE_PAL_CACHE_SUMMARY,
+        &config_pal_cache_summary,
+        sizeof(config_pal_cache_summary)
+    },
+    {  HOB_TYPE_PAL_MEM_ATTRIB,
+        &config_pal_mem_attrib,
+        sizeof(config_pal_mem_attrib)
+    },
+    {  HOB_TYPE_PAL_CACHE_INFO,
+        &config_pal_cache_info,
+        sizeof(config_pal_cache_info)
+    },
+    {  HOB_TYPE_PAL_CACHE_PROT_INFO,
+        &config_pal_cache_prot_info,
+        sizeof(config_pal_cache_prot_info)
+    },
+    {  HOB_TYPE_PAL_DEBUG_INFO,
+        &config_pal_debug_info,
+        sizeof(config_pal_debug_info)
+    },
+    {  HOB_TYPE_PAL_FIXED_ADDR,
+        &config_pal_fixed_addr,
+        sizeof(config_pal_fixed_addr)
+    },
+    {  HOB_TYPE_PAL_FREQ_BASE,
+        &config_pal_freq_base,
+        sizeof(config_pal_freq_base)
+    },
+    {  HOB_TYPE_PAL_FREQ_RATIOS,
+        &config_pal_freq_ratios,
+        sizeof(config_pal_freq_ratios)
+    },
+    {  HOB_TYPE_PAL_HALT_INFO,
+        &config_pal_halt_info,
+        sizeof(config_pal_halt_info)
+    },
+    {  HOB_TYPE_PAL_PERF_MON_INFO,
+        &config_pal_perf_mon_info,
+        sizeof(config_pal_perf_mon_info)
+    },
+    {  HOB_TYPE_PAL_PROC_GET_FEATURES,
+        &config_pal_proc_get_features,
+        sizeof(config_pal_proc_get_features)
+    },
+    {  HOB_TYPE_PAL_PTCE_INFO,
+        &config_pal_ptce_info,
+        sizeof(config_pal_ptce_info)
+    },
+    {  HOB_TYPE_PAL_REGISTER_INFO,
+        &config_pal_register_info,
+        sizeof(config_pal_register_info)
+    },
+    {  HOB_TYPE_PAL_RSE_INFO,
+        &config_pal_rse_info,
+        sizeof(config_pal_rse_info)
+    },
+    {  HOB_TYPE_PAL_TEST_INFO,
+        &config_pal_test_info,
+        sizeof(config_pal_test_info)
+    },
+    {  HOB_TYPE_PAL_VM_SUMMARY,
+        &config_pal_vm_summary,
+        sizeof(config_pal_vm_summary)
+    },
+    {  HOB_TYPE_PAL_VM_INFO,
+        &config_pal_vm_info,
+        sizeof(config_pal_vm_info)
+    },
+    {  HOB_TYPE_PAL_VM_PAGE_SIZE,
+        &config_pal_vm_page_size,
+        sizeof(config_pal_vm_page_size)
+    },      
+};
+
+static int add_pal_hob(void* hob_buf){
+    int i;
+    for (i=0; i<sizeof(hob_batch)/sizeof(hob_batch_t); i++){
+        if (hob_add(hob_buf, hob_batch[i].type, 
+                    hob_batch[i].data,
+                    hob_batch[i].size)<0)
+            return -1;
+    }
+    return 0;
+}
+
+static int setup_guest(  int xc_handle,
+                         uint32_t dom, unsigned long memsize,
+                         char *image, unsigned long image_size,
+                         unsigned int control_evtchn,
+                         unsigned int store_evtchn,
+                         unsigned long *store_mfn)
+{
+    unsigned long page_array[2];
+    shared_iopage_t *sp;
+    // FIXME: initialize pfn list for a temp hack
+    if (xc_ia64_get_pfn_list(xc_handle, dom, NULL, -1, -1) == -1) {
+       PERROR("Could not allocate continuous memory");
+       goto error_out;
+    }
+    
+    if ((image_size > 12 * MEM_M) || (image_size & (PAGE_SIZE - 1))) {
+        PERROR("Guest firmware size is incorrect [%ld]?", image_size);
+        return -1;
+    }
+
+    /* Load guest firmware */
+    if( xc_ia64_copy_to_domain_pages( xc_handle, dom, 
+            image, 4*MEM_G-image_size, image_size>>PAGE_SHIFT)) {
+        PERROR("Could not load guest firmware into domain");
+        goto error_out;
+    }
+
+    /* Hand-off state passed to guest firmware */
+    if (xc_ia64_build_hob(xc_handle, dom, memsize) < 0){
+        PERROR("Could not build hob\n");
+       goto error_out;
+    }
+
+    /* Retrieve special pages like io, xenstore, etc. */
+    if ( xc_ia64_get_pfn_list(xc_handle, dom, page_array, 
IO_PAGE_START>>PAGE_SHIFT, 2) != 2 )
+    {
+        PERROR("Could not get the page frame list");
+        goto error_out;
+    }
+
+    *store_mfn = page_array[1];
+    if ((sp = (shared_iopage_t *) xc_map_foreign_range(
+               xc_handle, dom, PAGE_SIZE, PROT_READ|PROT_WRITE,
+               page_array[0])) == 0)
+       goto error_out;
+    memset(sp, 0, PAGE_SIZE);
+    sp->sp_global.eport = control_evtchn;
+    munmap(sp, PAGE_SIZE);
+
+    return 0;
+
+ error_out:
+    return -1;
+}
+
+int xc_vmx_build(int xc_handle,
+                 uint32_t domid,
+                 int memsize,
+                 const char *image_name,
+                 unsigned int control_evtchn,
+                 unsigned int vcpus,
+                 unsigned int store_evtchn,
+                 unsigned long *store_mfn)
+{
+    dom0_op_t launch_op, op;
+    int rc ;
+    vcpu_guest_context_t st_ctxt, *ctxt = &st_ctxt;
+    char         *image = NULL;
+    unsigned long image_size;
+    unsigned long nr_pages;
+
+    if ( (nr_pages = xc_get_max_pages(xc_handle, domid)) < 0 )
+    {
+        PERROR("Could not find total pages for domain");
+        goto error_out;
+    }
+
+    if ( (image = xc_read_kernel_image(image_name, &image_size)) == NULL ){
+        PERROR("Could not read guest firmware image %s",image_name);
+        goto error_out;
+    }
+
+    image_size = (image_size + PAGE_SIZE - 1) & PAGE_MASK;
+
+    if ( mlock(&st_ctxt, sizeof(st_ctxt) ) ){   
+        PERROR("Unable to mlock ctxt");
+        return 1;
+    }
+
+    op.cmd = DOM0_GETDOMAININFO;
+    op.u.getdomaininfo.domain = (domid_t)domid;
+    if ( (do_dom0_op(xc_handle, &op) < 0) || 
+         ((uint16_t)op.u.getdomaininfo.domain != domid) ) {
+        PERROR("Could not get info on domain");
+        goto error_out;
+    }
+
+    if ( xc_domain_get_vcpu_context(xc_handle, domid, 0, ctxt) ){
+        PERROR("Could not get vcpu context");
+        goto error_out;
+    }
+
+    if ( !(op.u.getdomaininfo.flags & DOMFLAGS_PAUSED) ) {
+        ERROR("Domain is already constructed");
+        goto error_out;
+    }
+
+    if ( setup_guest(xc_handle, domid, (unsigned long)memsize, image, 
image_size, 
+                       control_evtchn, store_evtchn, store_mfn ) < 0 ){
+        ERROR("Error constructing guest OS");
+        goto error_out;
+    }
+
+    if ( image != NULL )
+        free(image);
+
+    ctxt->flags = VGCF_VMX_GUEST;
+    ctxt->regs.cr_iip = 0x80000000ffffffb0UL;
+    ctxt->vcpu.privregs = 0;
+
+    memset( &launch_op, 0, sizeof(launch_op) );
+
+    launch_op.u.setdomaininfo.domain = (domid_t)domid;
+    launch_op.u.setdomaininfo.vcpu   = 0;
+    launch_op.u.setdomaininfo.ctxt   = ctxt;
+
+    launch_op.cmd = DOM0_SETDOMAININFO;
+    rc = do_dom0_op(xc_handle, &launch_op);
+    return rc;
+
+ error_out:
+    if ( image != NULL )
+        free(image);
+
     return -1;
 }
 
diff -r dc36edf1102f -r bcccadcc56e5 tools/libxc/xc_linux_build.c
--- a/tools/libxc/xc_linux_build.c      Sun Oct 30 12:52:38 2005
+++ b/tools/libxc/xc_linux_build.c      Sun Oct 30 13:00:35 2005
@@ -350,6 +350,8 @@
     start_info = xc_map_foreign_range(
         xc_handle, dom, PAGE_SIZE, PROT_READ|PROT_WRITE, page_array[0]);
     memset(start_info, 0, sizeof(*start_info));
+    rc = xc_version(xc_handle, XENVER_version, NULL);
+    sprintf(start_info->magic, "Xen-%i.%i", rc >> 16, rc & (0xFFFF));
     start_info->flags        = flags;
     start_info->store_mfn    = nr_pages - 2;
     start_info->store_evtchn = store_evtchn;
@@ -624,6 +626,8 @@
         xc_handle, dom, PAGE_SIZE, PROT_READ|PROT_WRITE,
         page_array[(vstartinfo_start-dsi.v_start)>>PAGE_SHIFT]);
     memset(start_info, 0, sizeof(*start_info));
+    rc = xc_version(xc_handle, XENVER_version, NULL);
+    sprintf(start_info->magic, "Xen-%i.%i", rc >> 16, rc & (0xFFFF));
     start_info->nr_pages     = nr_pages;
     start_info->shared_info  = shared_info_frame << PAGE_SHIFT;
     start_info->flags        = flags;
diff -r dc36edf1102f -r bcccadcc56e5 tools/libxc/xc_private.c
--- a/tools/libxc/xc_private.c  Sun Oct 30 12:52:38 2005
+++ b/tools/libxc/xc_private.c  Sun Oct 30 13:00:35 2005
@@ -313,46 +313,6 @@
     return (ret < 0) ? -1 : op.u.getmemlist.num_pfns;
 }
 
-#ifdef __ia64__
-int xc_ia64_get_pfn_list(int xc_handle,
-                         uint32_t domid, 
-                         unsigned long *pfn_buf, 
-                         unsigned int start_page,
-                         unsigned int nr_pages)
-{
-    dom0_op_t op;
-    int ret;
-
-    op.cmd = DOM0_GETMEMLIST;
-    op.u.getmemlist.domain   = (domid_t)domid;
-    op.u.getmemlist.max_pfns = ((unsigned long)start_page << 32) | nr_pages;
-    op.u.getmemlist.buffer   = pfn_buf;
-
-    if ( mlock(pfn_buf, nr_pages * sizeof(unsigned long)) != 0 )
-    {
-        PERROR("Could not lock pfn list buffer");
-        return -1;
-    }    
-
-    /* XXX Hack to put pages in TLB, hypervisor should be able to handle this 
*/
-    memset(pfn_buf, 0, nr_pages * sizeof(unsigned long));
-    ret = do_dom0_op(xc_handle, &op);
-
-    (void)munlock(pfn_buf, nr_pages * sizeof(unsigned long));
-
-    return (ret < 0) ? -1 : op.u.getmemlist.num_pfns;
-}
-
-long xc_get_max_pages(int xc_handle, uint32_t domid)
-{
-    dom0_op_t op;
-    op.cmd = DOM0_GETDOMAININFO;
-    op.u.getdomaininfo.domain = (domid_t)domid;
-    return (do_dom0_op(xc_handle, &op) < 0) ? 
-        -1 : op.u.getdomaininfo.max_pages;
-}
-#endif
-
 long xc_get_tot_pages(int xc_handle, uint32_t domid)
 {
     dom0_op_t op;
diff -r dc36edf1102f -r bcccadcc56e5 tools/libxc/xc_vmx_build.c
--- a/tools/libxc/xc_vmx_build.c        Sun Oct 30 12:52:38 2005
+++ b/tools/libxc/xc_vmx_build.c        Sun Oct 30 13:00:35 2005
@@ -279,6 +279,7 @@
                        vcpu_guest_context_t *ctxt,
                        unsigned long shared_info_frame,
                        unsigned int control_evtchn,
+                       unsigned int lapic,
                        unsigned int vcpus,
                        unsigned int store_evtchn,
                        unsigned long *store_mfn)
@@ -554,7 +555,7 @@
     ctxt->user_regs.eax = 0;
     ctxt->user_regs.esp = 0;
     ctxt->user_regs.ebx = 0; /* startup_32 expects this to be 0 to signal boot 
cpu */
-    ctxt->user_regs.ecx = 0;
+    ctxt->user_regs.ecx = lapic;
     ctxt->user_regs.esi = 0;
     ctxt->user_regs.edi = 0;
     ctxt->user_regs.ebp = 0;
@@ -597,6 +598,7 @@
                  int memsize,
                  const char *image_name,
                  unsigned int control_evtchn,
+                 unsigned int lapic,
                  unsigned int vcpus,
                  unsigned int store_evtchn,
                  unsigned long *store_mfn)
@@ -651,9 +653,9 @@
         goto error_out;
     }
 
-    if ( setup_guest(xc_handle, domid, memsize, image, image_size,
-                     nr_pages, ctxt, op.u.getdomaininfo.shared_info_frame,
-                     control_evtchn, vcpus, store_evtchn, store_mfn) < 0)
+    if ( setup_guest(xc_handle, domid, memsize, image, image_size, nr_pages,
+                     ctxt, op.u.getdomaininfo.shared_info_frame, 
control_evtchn,
+                     lapic, vcpus, store_evtchn, store_mfn) < 0)
     {
         ERROR("Error constructing guest OS");
         goto error_out;
diff -r dc36edf1102f -r bcccadcc56e5 tools/libxc/xenctrl.h
--- a/tools/libxc/xenctrl.h     Sun Oct 30 12:52:38 2005
+++ b/tools/libxc/xenctrl.h     Sun Oct 30 13:00:35 2005
@@ -414,6 +414,12 @@
                          unsigned long *pfn_buf, 
                          unsigned int start_page, unsigned int nr_pages);
 
+int xc_copy_to_domain_page(int xc_handle, uint32_t domid,
+                          unsigned long dst_pfn, void *src_page);
+
+int xc_ia64_copy_to_domain_pages(int xc_handle, uint32_t domid,
+        void* src_page, unsigned long dst_pfn, int nr_pages);
+
 long xc_get_max_pages(int xc_handle, uint32_t domid);
 
 int xc_mmuext_op(int xc_handle, struct mmuext_op *op, unsigned int nr_ops,
diff -r dc36edf1102f -r bcccadcc56e5 tools/libxc/xenguest.h
--- a/tools/libxc/xenguest.h    Sun Oct 30 12:52:38 2005
+++ b/tools/libxc/xenguest.h    Sun Oct 30 13:00:35 2005
@@ -56,6 +56,7 @@
                  int memsize,
                  const char *image_name,
                  unsigned int control_evtchn,
+                 unsigned int lapic,
                  unsigned int vcpus,
                  unsigned int store_evtchn,
                  unsigned long *store_mfn);
diff -r dc36edf1102f -r bcccadcc56e5 tools/misc/cpuperf/cpuperf.c
--- a/tools/misc/cpuperf/cpuperf.c      Sun Oct 30 12:52:38 2005
+++ b/tools/misc/cpuperf/cpuperf.c      Sun Oct 30 13:00:35 2005
@@ -16,7 +16,6 @@
 
 #include <sys/types.h>
 #include <sched.h>
-#include <error.h>
 #include <stdio.h>
 #include <unistd.h>
 #include <stdlib.h>
diff -r dc36edf1102f -r bcccadcc56e5 tools/misc/miniterm/miniterm.c
--- a/tools/misc/miniterm/miniterm.c    Sun Oct 30 12:52:38 2005
+++ b/tools/misc/miniterm/miniterm.c    Sun Oct 30 13:00:35 2005
@@ -29,7 +29,7 @@
 #include <stdlib.h>
 #include <unistd.h>
 #include <fcntl.h>
-#include <sys/signal.h>
+#include <signal.h>
 #include <sys/types.h>
 #include <sys/wait.h>
 
diff -r dc36edf1102f -r bcccadcc56e5 tools/python/xen/lowlevel/xc/xc.c
--- a/tools/python/xen/lowlevel/xc/xc.c Sun Oct 30 12:52:38 2005
+++ b/tools/python/xen/lowlevel/xc/xc.c Sun Oct 30 13:00:35 2005
@@ -438,19 +438,20 @@
     char *image;
     int control_evtchn, store_evtchn;
     int vcpus = 1;
+    int lapic = 0;
     int memsize;
     unsigned long store_mfn = 0;
 
     static char *kwd_list[] = { "dom", "control_evtchn", "store_evtchn",
-                                "memsize", "image", "vcpus", NULL };
-
-    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "iiiisi", kwd_list,
+                                "memsize", "image", "lapic", "vcpus", NULL };
+
+    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "iiiisii", kwd_list,
                                       &dom, &control_evtchn, &store_evtchn,
-                                      &memsize, &image, &vcpus) )
+                                      &memsize, &image, &lapic, &vcpus) )
         return NULL;
 
     if ( xc_vmx_build(xc->xc_handle, dom, memsize, image, control_evtchn,
-                      vcpus, store_evtchn, &store_mfn) != 0 )
+                      lapic, vcpus, store_evtchn, &store_mfn) != 0 )
         return PyErr_SetFromErrno(xc_error);
 
     return Py_BuildValue("{s:i}", "store_mfn", store_mfn);
diff -r dc36edf1102f -r bcccadcc56e5 tools/python/xen/web/tcp.py
--- a/tools/python/xen/web/tcp.py       Sun Oct 30 12:52:38 2005
+++ b/tools/python/xen/web/tcp.py       Sun Oct 30 13:00:35 2005
@@ -99,7 +99,7 @@
     return l
 
 def SetCloExec(SocketListener):
-    SocketListener.SetCloExec()
+    SocketListener.setCloExec()
 
 def connectTCP(host, port, factory, timeout=None, bindAddress=None):
     c = TCPConnector(host, port, factory, timeout=timeout, 
bindAddress=bindAddress)
diff -r dc36edf1102f -r bcccadcc56e5 tools/python/xen/xend/image.py
--- a/tools/python/xen/xend/image.py    Sun Oct 30 12:52:38 2005
+++ b/tools/python/xen/xend/image.py    Sun Oct 30 13:00:35 2005
@@ -203,6 +203,10 @@
 
         self.dmargs += self.configVNC(imageConfig)
 
+        self.lapic = 0
+        lapic = sxp.child_value(imageConfig, 'lapic')
+        if not lapic is None:
+            self.lapic = int(lapic)
 
     def buildDomain(self):
         # Create an event channel
@@ -217,6 +221,7 @@
         log.debug("control_evtchn = %d", self.device_channel)
         log.debug("store_evtchn   = %d", store_evtchn)
         log.debug("memsize        = %d", self.vm.getMemoryTarget() / 1024)
+        log.debug("lapic          = %d", self.lapic)
         log.debug("vcpus          = %d", self.vm.getVCpuCount())
 
         return xc.vmx_build(dom            = self.vm.getDomid(),
@@ -224,6 +229,7 @@
                             control_evtchn = self.device_channel,
                             store_evtchn   = store_evtchn,
                             memsize        = self.vm.getMemoryTarget() / 1024,
+                            lapic          = self.lapic,
                             vcpus          = self.vm.getVCpuCount())
 
 
@@ -342,12 +348,15 @@
 
     def getDomainMemory(self, mem):
         """@see ImageHandler.getDomainMemory"""
+       page_kb = 4
+       if os.uname()[4] == 'ia64':
+           page_kb = 16
         # for ioreq_t and xenstore
         static_pages = 2
-        return mem + self.getPageTableSize(mem / 1024) + 4 * static_pages
+        return mem + (self.getPageTableSize(mem / 1024) + static_pages) * 
page_kb
             
     def getPageTableSize(self, mem_mb):
-        """Return the size of memory needed for 1:1 page tables for physical
+        """Return the pages of memory needed for 1:1 page tables for physical
            mode.
 
         @param mem_mb: size in MB
@@ -355,13 +364,13 @@
         """
         # 1 page for the PGD + 1 pte page for 4MB of memory (rounded)
         if os.uname()[4] == 'x86_64':
-            return (5 + ((mem_mb + 1) >> 1)) * 4
+            return 5 + ((mem_mb + 1) >> 1)
         elif os.uname()[4] == 'ia64':
-            # XEN/IA64 has p2m table allocated on demand, so only return
-            # guest firmware size here.
-            return 16 * 1024
+            # 1:1 pgtable is allocated on demand ia64, so just return rom size
+           # for guest firmware
+            return 1024
         else:
-            return (1 + ((mem_mb + 3) >> 2)) * 4
+            return 1 + ((mem_mb + 3) >> 2)
 
 
 """Table of image handler classes for virtual machine images.  Indexed by
diff -r dc36edf1102f -r bcccadcc56e5 tools/python/xen/xend/server/event.py
--- a/tools/python/xen/xend/server/event.py     Sun Oct 30 12:52:38 2005
+++ b/tools/python/xen/xend/server/event.py     Sun Oct 30 13:00:35 2005
@@ -192,4 +192,5 @@
     if xroot.get_xend_http_server():
         port = xroot.get_xend_event_port()
         interface = xroot.get_xend_address()
-        tcp.listenTCP(port, factory, interface=interface)
+        l = tcp.listenTCP(port, factory, interface=interface)
+        l.setCloExec()
diff -r dc36edf1102f -r bcccadcc56e5 tools/python/xen/xm/create.py
--- a/tools/python/xen/xm/create.py     Sun Oct 30 12:52:38 2005
+++ b/tools/python/xen/xm/create.py     Sun Oct 30 13:00:35 2005
@@ -157,6 +157,10 @@
           fn=set_int, default=None,
           use="CPU to run the domain on.")
 
+gopts.var('lapic', val='LAPIC',
+          fn=set_int, default=0,
+          use="Disable or enable local APIC of VMX domain.")
+
 gopts.var('vcpus', val='VCPUS',
           fn=set_int, default=1,
           use="# of Virtual CPUS in domain.")
@@ -314,10 +318,6 @@
 gopts.var('nfs_root', val="PATH",
           fn=set_value, default=None,
           use="Set the path of the root NFS directory.")
-
-gopts.var('memmap', val='FILE',
-          fn=set_value, default='',
-          use="Path to memap SXP file.")
 
 gopts.var('device_model', val='FILE',
           fn=set_value, default='',
@@ -556,9 +556,9 @@
 def configure_vmx(config_image, vals):
     """Create the config for VMX devices.
     """
-    args = [ 'memmap', 'device_model', 'vcpus', 'cdrom',
-             'boot', 'fda', 'fdb', 'localtime', 'serial', 'macaddr', 'stdvga', 
-             'isa', 'nographic', 'vnc', 'vncviewer', 'sdl', 'display', 
'ne2000']
+    args = [ 'device_model', 'vcpus', 'cdrom', 'boot', 'fda', 'fdb',
+             'localtime', 'serial', 'macaddr', 'stdvga', 'isa', 'nographic',
+             'vnc', 'vncviewer', 'sdl', 'display', 'ne2000', 'lapic']
     for a in args:
         if (vals.__dict__[a]):
             config_image.append([a, vals.__dict__[a]])
diff -r dc36edf1102f -r bcccadcc56e5 tools/python/xen/xm/main.py
--- a/tools/python/xen/xm/main.py       Sun Oct 30 12:52:38 2005
+++ b/tools/python/xen/xm/main.py       Sun Oct 30 13:00:35 2005
@@ -61,6 +61,8 @@
     top                     monitor system and domains in real-time
     unpause <DomId>         unpause a paused domain
 
+<DomName> can be substituted for <DomId> in xm subcommands.
+
 For a complete list of subcommands run 'xm help --long'
 For more help on xm see the xm(1) man page
 For more help on xm create, see the xmdomain.cfg(5) man page"""
@@ -118,6 +120,8 @@
     vnet-list   [-l|--long]    list vnets
     vnet-create <config>       create a vnet from a config file
     vnet-delete <vnetid>       delete a vnet
+
+<DomName> can be substituted for <DomId> in xm subcommands.
 
 For a short list of subcommands run 'xm help'
 For more help on xm see the xm(1) man page
diff -r dc36edf1102f -r bcccadcc56e5 tools/security/getlabel.sh
--- a/tools/security/getlabel.sh        Sun Oct 30 12:52:38 2005
+++ b/tools/security/getlabel.sh        Sun Oct 30 13:00:35 2005
@@ -36,18 +36,21 @@
 
 usage ()
 {
-       echo "Usage: $0 -sid <ssidref> [<policy name>] or"
-       echo "       $0 -dom <domid>   [<policy name>]  "
-       echo ""
-       echo "policy name : the name of the policy, i.e. 'chwall'"
-       echo "              If the policy name is omitted, the grub.conf"
-       echo "              entry of the running system is tried to be read"
-       echo "              and the policy name determined from there."
-       echo "ssidref     : an ssidref in hex or decimal format, i.e., 
'0x00010002'"
-       echo "              or '65538'"
-       echo "domid       : id of the domain, i.e., '1'; Use numbers from the 
2nd"
-       echo "              column shown when invoking 'xm list'"
-       echo ""
+echo "Use this tool to display the label of a domain or the label that is
+corresponding to an ssidref given the name of the running policy.
+
+Usage: $0 -sid <ssidref> [<policy name>] or
+       $0 -dom <domid>   [<policy name>]
+
+policy name : the name of the policy, i.e. 'chwall'
+              If the policy name is omitted, the grub.conf
+              entry of the running system is tried to be read
+              and the policy name determined from there.
+ssidref     : an ssidref in hex or decimal format, i.e., '0x00010002'
+              or '65538'
+domid       : id of the domain, i.e., '1'; Use numbers from the 2nd
+              column shown when invoking 'xm list'
+"
 }
 
 
diff -r dc36edf1102f -r bcccadcc56e5 tools/security/setlabel.sh
--- a/tools/security/setlabel.sh        Sun Oct 30 12:52:38 2005
+++ b/tools/security/setlabel.sh        Sun Oct 30 13:00:35 2005
@@ -39,21 +39,27 @@
 
 usage ()
 {
-       echo "Usage: $0 [Option] <vmfile> <label> [<policy name>]"
-       echo "    or $0 -l [<policy name>]"
-       echo ""
-       echo "Valid options are:"
-       echo "-r          : to relabel a file without being prompted"
-       echo ""
-       echo "vmfile      : XEN vm configuration file"
-       echo "label       : the label to map to an ssidref"
-       echo "policy name : the name of the policy, i.e. 'chwall'"
-       echo "              If the policy name is omitted, it is attempted"
-       echo "              to find the current policy's name in grub.conf."
-       echo ""
-       echo "-l [<policy name>] is used to show valid labels in the map file 
of"
-       echo "                   the given or current policy."
-       echo ""
+echo "Use this tool to put the ssidref corresponding to a label of a policy 
into
+the VM configuration file, or use it to display all labels of a policy.
+
+Usage: $0 [Option] <vmfile> <label> [<policy name>]
+    or $0 -l [<policy name>]
+
+Valid options are:
+-r          : to relabel a file without being prompted
+
+vmfile      : XEN vm configuration file; give complete path
+label       : the label to map to an ssidref
+policy name : the name of the policy, i.e. 'chwall'
+              If the policy name is omitted, it is attempted
+              to find the current policy's name in grub.conf.
+
+-l [<policy name>] is used to show valid labels in the map file of
+                   the given or current policy. If the policy name
+                   is omitted, it will be tried to determine the
+                   current policy from grub.conf (/boot/grub/grub.conf)
+
+"
 }
 
 
@@ -83,7 +89,7 @@
                        exit -1;
                fi
        else
-               policy=$3;
+               policy=$1;
        fi
 
 
@@ -92,7 +98,7 @@
        if [ "$res" != "0" ]; then
                showLabels $mapfile
        else
-               echo "Could not find map file for policy '$1'."
+               echo "Could not find map file for policy '$policy'."
        fi
 elif [ "$mode" == "usage" ]; then
        usage
diff -r dc36edf1102f -r bcccadcc56e5 tools/security/updategrub.sh
--- a/tools/security/updategrub.sh      Sun Oct 30 12:52:38 2005
+++ b/tools/security/updategrub.sh      Sun Oct 30 13:00:35 2005
@@ -26,11 +26,16 @@
 # Show usage of this program
 usage ()
 {
-       echo "Usage: $0 <policy name> <root of xen repository>"
-       echo ""
-       echo "<policy name>             : The name of the policy, i.e. xen_null"
-       echo "<root of xen repository>  : The root of the XEN repositrory."
-       echo ""
+echo "Use this tool to add the binary policy to the Xen grub entry and
+have Xen automatically enforce the policy when starting.
+
+Usage: $0 <policy name> <root of xen repository>
+
+<policy name>             : The name of the policy, i.e. xen_null
+<root of xen repository>  : The root of the XEN repository. Give
+                            complete path.
+
+"
 }
 
 # This function sets the global variable 'linux'
@@ -43,11 +48,24 @@
        for f in $path/linux-*-xen0 ; do
                versionfile=$f/include/linux/version.h
                if [ -r $versionfile ]; then
-                       lnx=`cat $versionfile | \
-                            grep UTS_RELEASE | \
-                            awk '{             \
-                              len=length($3);  \
-                              print substr($3,2,len-2) }'`
+                       lnx=`cat $versionfile |                \
+                            grep UTS_RELEASE |                \
+                            awk '{                            \
+                              len=length($3);                 \
+                              version=substr($3,2,len-2);     \
+                              split(version,numbers,".");     \
+                              if (numbers[4]=="") {           \
+                                printf("%s.%s.%s",            \
+                                        numbers[1],           \
+                                        numbers[2],           \
+                                        numbers[3]);          \
+                              } else {                        \
+                                printf("%s.%s.%s[.0-9]*-xen0",\
+                                       numbers[1],            \
+                                       numbers[2],            \
+                                       numbers[3]);           \
+                              }                               \
+                            }'`
                fi
                if [ "$lnx" != "" ]; then
                        linux="[./0-9a-zA-z]*$lnx"
@@ -143,10 +161,19 @@
                echo "Could not create temporary file! Aborting."
                exit -1
        fi
-       mv -f $tmpfile $grubconf
+       diff $tmpfile $grubconf > /dev/null
+       RES=$?
+       if [ "$RES" == "0" ]; then
+               echo "No changes were made to $grubconf."
+       else
+               echo "Successfully updated $grubconf."
+               mv -f $tmpfile $grubconf
+       fi
 }
 
 if [ "$1" == "" -o "$2" == "" ]; then
+       echo "Error: Not enough command line parameters."
+       echo ""
        usage
        exit -1
 fi
diff -r dc36edf1102f -r bcccadcc56e5 tools/xenstore/Makefile
--- a/tools/xenstore/Makefile   Sun Oct 30 12:52:38 2005
+++ b/tools/xenstore/Makefile   Sun Oct 30 13:00:35 2005
@@ -77,7 +77,7 @@
 clean: testsuite-clean
        rm -f *.o *.opic *.so
        rm -f xenstored xs_random xs_stress xs_crashme
-       rm -f xs_test xenstored_test
+       rm -f xs_test xenstored_test xs_tdb_dump
        $(RM) $(PROG_DEP)
 
 print-dir:
diff -r dc36edf1102f -r bcccadcc56e5 xen/acm/acm_simple_type_enforcement_hooks.c
--- a/xen/acm/acm_simple_type_enforcement_hooks.c       Sun Oct 30 12:52:38 2005
+++ b/xen/acm/acm_simple_type_enforcement_hooks.c       Sun Oct 30 13:00:35 2005
@@ -392,8 +392,11 @@
     int i;
 
     printkd("checking cache: %x --> %x.\n", dom->domain_id, rdom);
+
+    if (dom->ssid == NULL)
+        return 0;
     ste_ssid = GET_SSIDP(ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY, 
-                         (struct acm_ssid_domain *)(dom)->ssid);
+                         (struct acm_ssid_domain *)(dom->ssid));
 
     for(i=0; i< ACM_TE_CACHE_SIZE; i++) {
         if ((ste_ssid->ste_cache[i].valid == VALID) &&
@@ -412,6 +415,8 @@
     struct ste_ssid *ste_ssid;
     int i;
     printkd("caching from doms: %x --> %x.\n", subj->domain_id, 
obj->domain_id);
+    if (subj->ssid == NULL)
+        return;
     ste_ssid = GET_SSIDP(ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY, 
                          (struct acm_ssid_domain *)(subj)->ssid);
     for(i=0; i< ACM_TE_CACHE_SIZE; i++)
@@ -431,26 +436,34 @@
     struct ste_ssid *ste_ssid;
     int i;
     struct domain **pd;
+    struct acm_ssid_domain *ssid;
 
     printkd("deleting cache for dom %x.\n", id);
-
     read_lock(&domlist_lock); /* look through caches of all domains */
     pd = &domain_list;
     for ( pd = &domain_list; *pd != NULL; pd = &(*pd)->next_in_list ) {
-        ste_ssid = GET_SSIDP(ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY, 
-                             (struct acm_ssid_domain *)(*pd)->ssid);
+        ssid = (struct acm_ssid_domain *)((*pd)->ssid);
+
+        if (ssid == NULL)
+            continue; /* hanging domain structure, no ssid any more ... */
+        ste_ssid = GET_SSIDP(ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY, ssid);
+        if (!ste_ssid) {
+            printk("%s: deleting ID from cache ERROR (no ste_ssid)!\n",
+                   __func__);
+            goto out;
+        }
         for (i=0; i<ACM_TE_CACHE_SIZE; i++)
             if ((ste_ssid->ste_cache[i].valid == VALID) &&
-                (ste_ssid->ste_cache[i].id = id))
+                (ste_ssid->ste_cache[i].id == id))
                 ste_ssid->ste_cache[i].valid = FREE;
     }
+ out:
     read_unlock(&domlist_lock);
 }
 
 /***************************
  * Authorization functions
  **************************/
-
 static int 
 ste_pre_domain_create(void *subject_ssid, ssidref_t ssidref)
 {      
@@ -484,19 +497,29 @@
 
 /* -------- EVENTCHANNEL OPERATIONS -----------*/
 static int
-ste_pre_eventchannel_unbound(domid_t id) {
+ste_pre_eventchannel_unbound(domid_t id1, domid_t id2) {
     struct domain *subj, *obj;
     int ret;
-    traceprintk("%s: dom%x-->dom%x.\n", 
-                __func__, current->domain->domain_id, id);
-
-    if (check_cache(current->domain, id)) {
+    traceprintk("%s: dom%x-->dom%x.\n", __func__,
+                (id1 == DOMID_SELF) ? current->domain->domain_id : id1,
+                (id2 == DOMID_SELF) ? current->domain->domain_id : id2);
+
+    if (id1 == DOMID_SELF) id1 = current->domain->domain_id;
+    if (id2 == DOMID_SELF) id2 = current->domain->domain_id;
+
+    subj = find_domain_by_id(id1);
+    obj  = find_domain_by_id(id2);
+    if ((subj == NULL) || (obj == NULL)) {
+        ret = ACM_ACCESS_DENIED;
+        goto out;
+    }
+    /* cache check late */
+    if (check_cache(subj, obj->domain_id)) {
         atomic_inc(&ste_bin_pol.ec_cachehit_count);
-        return ACM_ACCESS_PERMITTED;
+        ret = ACM_ACCESS_PERMITTED;
+        goto out;
     }
     atomic_inc(&ste_bin_pol.ec_eval_count);
-    subj = current->domain;
-    obj = find_domain_by_id(id);
 
     if (share_common_type(subj, obj)) {
         cache_result(subj, obj);
@@ -505,38 +528,43 @@
         atomic_inc(&ste_bin_pol.ec_denied_count); 
         ret = ACM_ACCESS_DENIED; 
     }
+  out:
     if (obj != NULL)
         put_domain(obj);
+    if (subj != NULL)
+        put_domain(subj);
     return ret;
 }
 
 static int
-ste_pre_eventchannel_interdomain(domid_t id1, domid_t id2)
-{
-    struct domain *subj, *obj;
+ste_pre_eventchannel_interdomain(domid_t id)
+{
+    struct domain *subj=NULL, *obj=NULL;
     int ret;
+
     traceprintk("%s: dom%x-->dom%x.\n", __func__,
-                (id1 == DOMID_SELF) ? current->domain->domain_id : id1,
-                (id2 == DOMID_SELF) ? current->domain->domain_id : id2);
+                current->domain->domain_id,
+                (id == DOMID_SELF) ? current->domain->domain_id : id);
 
     /* following is a bit longer but ensures that we
      * "put" only domains that we where "find"-ing 
      */
-    if (id1 == DOMID_SELF) id1 = current->domain->domain_id;
-    if (id2 == DOMID_SELF) id2 = current->domain->domain_id;
-
-    subj = find_domain_by_id(id1);
-    obj  = find_domain_by_id(id2);
-    if ((subj == NULL) || (obj == NULL)) {
+    if (id == DOMID_SELF) id = current->domain->domain_id;
+
+    subj = current->domain;
+    obj  = find_domain_by_id(id);
+    if (obj == NULL) {
         ret = ACM_ACCESS_DENIED;
         goto out;
     }
+
     /* cache check late, but evtchn is not on performance critical path */
     if (check_cache(subj, obj->domain_id)) {
         atomic_inc(&ste_bin_pol.ec_cachehit_count);
         ret = ACM_ACCESS_PERMITTED;
         goto out;
     }
+
     atomic_inc(&ste_bin_pol.ec_eval_count);
 
     if (share_common_type(subj, obj)) {
@@ -549,8 +577,6 @@
  out:
     if (obj != NULL)
         put_domain(obj);
-    if (subj != NULL)
-        put_domain(subj);
     return ret;
 }
 
diff -r dc36edf1102f -r bcccadcc56e5 xen/arch/ia64/asm-offsets.c
--- a/xen/arch/ia64/asm-offsets.c       Sun Oct 30 12:52:38 2005
+++ b/xen/arch/ia64/asm-offsets.c       Sun Oct 30 13:00:35 2005
@@ -59,6 +59,8 @@
        DEFINE(XSI_BANKNUM_OFS, offsetof(mapped_regs_t, banknum));
        DEFINE(XSI_BANK0_OFS, offsetof(mapped_regs_t, bank0_regs[0]));
        DEFINE(XSI_BANK1_OFS, offsetof(mapped_regs_t, bank1_regs[0]));
+       DEFINE(XSI_B0NATS_OFS, offsetof(mapped_regs_t, vbnat));
+       DEFINE(XSI_B1NATS_OFS, offsetof(mapped_regs_t, vnat));
        DEFINE(XSI_RR0_OFS, offsetof(mapped_regs_t, rrs[0]));
        DEFINE(XSI_METAPHYS_OFS, offsetof(mapped_regs_t, metaphysical_mode));
        DEFINE(XSI_PRECOVER_IFS_OFS, offsetof(mapped_regs_t, precover_ifs));
@@ -79,13 +81,17 @@
        //DEFINE(IA64_TASK_SIGHAND_OFFSET,offsetof (struct task_struct, 
sighand));
        //DEFINE(IA64_TASK_SIGNAL_OFFSET,offsetof (struct task_struct, signal));
        //DEFINE(IA64_TASK_TGID_OFFSET, offsetof (struct task_struct, tgid));
+       DEFINE(IA64_PGD, offsetof(struct domain, arch.mm));
        DEFINE(IA64_TASK_THREAD_KSP_OFFSET, offsetof (struct vcpu, 
arch._thread.ksp));
        DEFINE(IA64_TASK_THREAD_ON_USTACK_OFFSET, offsetof (struct vcpu, 
arch._thread.on_ustack));
 
+       DEFINE(IA64_VCPU_DOMAIN_OFFSET, offsetof (struct vcpu, domain));
        DEFINE(IA64_VCPU_META_RR0_OFFSET, offsetof (struct vcpu, 
arch.metaphysical_rr0));
        DEFINE(IA64_VCPU_META_SAVED_RR0_OFFSET, offsetof (struct vcpu, 
arch.metaphysical_saved_rr0));
        DEFINE(IA64_VCPU_BREAKIMM_OFFSET, offsetof (struct vcpu, 
arch.breakimm));
        DEFINE(IA64_VCPU_IVA_OFFSET, offsetof (struct vcpu, arch.iva));
+       DEFINE(IA64_VCPU_DTLB_PTE_OFFSET, offsetof (struct vcpu, 
arch.dtlb_pte));
+       DEFINE(IA64_VCPU_ITLB_PTE_OFFSET, offsetof (struct vcpu, 
arch.itlb_pte));
        DEFINE(IA64_VCPU_IRR0_OFFSET, offsetof (struct vcpu, arch.irr[0]));
        DEFINE(IA64_VCPU_IRR3_OFFSET, offsetof (struct vcpu, arch.irr[3]));
        DEFINE(IA64_VCPU_INSVC3_OFFSET, offsetof (struct vcpu, arch.insvc[3]));
diff -r dc36edf1102f -r bcccadcc56e5 xen/arch/ia64/linux-xen/entry.S
--- a/xen/arch/ia64/linux-xen/entry.S   Sun Oct 30 12:52:38 2005
+++ b/xen/arch/ia64/linux-xen/entry.S   Sun Oct 30 13:00:35 2005
@@ -900,10 +900,17 @@
     adds r7 = PT(EML_UNAT)+16,r12
        ;;
     ld8 r7 = [r7]
+       ;;
+#if 0
+leave_kernel_self:
+    cmp.ne p8,p0 = r0, r7
+(p8) br.sptk.few leave_kernel_self
+       ;; 
+#endif
 (p6)   br.call.sptk.many b0=deliver_pending_interrupt
     ;;
        mov ar.pfs=loc0
-    mov ar.unat=r7  /* load eml_unat  */
+       mov ar.unat=r7  /* load eml_unat  */
        mov r31=r0
 
 
diff -r dc36edf1102f -r bcccadcc56e5 xen/arch/ia64/linux-xen/head.S
--- a/xen/arch/ia64/linux-xen/head.S    Sun Oct 30 12:52:38 2005
+++ b/xen/arch/ia64/linux-xen/head.S    Sun Oct 30 13:00:35 2005
@@ -324,6 +324,9 @@
        mov r16=-1
 (isBP) br.cond.dpnt .load_current // BP stack is on region 5 --- no need to 
map it
 
+#ifndef XEN
+       // XEN: stack is allocated in xenheap, which is currently always
+       //  mapped.
        // load mapping for stack (virtaddr in r2, physaddr in r3)
        rsm psr.ic
        movl r17=PAGE_KERNEL
@@ -353,7 +356,8 @@
        ssm psr.ic
        srlz.d
        ;;
-
+#endif
+       
 .load_current:
        // load the "current" pointer (r13) and ar.k6 with the current task
 #if defined(XEN) && defined(VALIDATE_VT)
diff -r dc36edf1102f -r bcccadcc56e5 xen/arch/ia64/linux-xen/irq_ia64.c
--- a/xen/arch/ia64/linux-xen/irq_ia64.c        Sun Oct 30 12:52:38 2005
+++ b/xen/arch/ia64/linux-xen/irq_ia64.c        Sun Oct 30 13:00:35 2005
@@ -281,5 +281,8 @@
        ipi_data = (delivery_mode << 8) | (vector & 0xff);
        ipi_addr = ipi_base_addr + ((phys_cpu_id << 4) | ((redirect & 1) << 3));
 
+#ifdef XEN
+       printf ("send_ipi to %d (%x)\n", cpu, phys_cpu_id);
+#endif
        writeq(ipi_data, ipi_addr);
 }
diff -r dc36edf1102f -r bcccadcc56e5 xen/arch/ia64/linux-xen/mm_contig.c
--- a/xen/arch/ia64/linux-xen/mm_contig.c       Sun Oct 30 12:52:38 2005
+++ b/xen/arch/ia64/linux-xen/mm_contig.c       Sun Oct 30 13:00:35 2005
@@ -193,8 +193,8 @@
         */
        if (smp_processor_id() == 0) {
 #ifdef XEN
-               cpu_data = alloc_xenheap_pages(PERCPU_PAGE_SHIFT -
-                       PAGE_SHIFT + get_order(NR_CPUS));
+               cpu_data = alloc_xenheap_pages(get_order(NR_CPUS
+                                                        * PERCPU_PAGE_SIZE));
 #else
                cpu_data = __alloc_bootmem(PERCPU_PAGE_SIZE * NR_CPUS,
                                           PERCPU_PAGE_SIZE, 
__pa(MAX_DMA_ADDRESS)