Index: kernel/arch/xen32/include/asm.h
===================================================================
--- kernel/arch/xen32/include/asm.h	(revision 7d3d641a8c852bac56e8c9ace15cfffbdf4b0173)
+++ kernel/arch/xen32/include/asm.h	(revision 5b23a82c8d68ae8b01f1fbb9ace30e2377050d55)
@@ -39,4 +39,5 @@
 #include <arch/pm.h>
 #include <arch/types.h>
+#include <arch/barrier.h>
 #include <config.h>
 
@@ -151,11 +152,13 @@
 static inline ipl_t interrupts_enable(void)
 {
-	ipl_t v = 0;
-/*	__asm__ volatile (
-		"pushf\n\t"
-		"popl %0\n\t"
-		"sti\n"
-		: "=r" (v)
-	);*/
+	// FIXME SMP
+	
+	ipl_t v = shared_info.vcpu_info[0].evtchn_upcall_mask;
+	write_barrier();
+	shared_info.vcpu_info[0].evtchn_upcall_mask = 0;
+	write_barrier();
+	if (shared_info.vcpu_info[0].evtchn_upcall_pending)
+		force_evtchn_callback();
+	
 	return v;
 }
@@ -170,11 +173,10 @@
 static inline ipl_t interrupts_disable(void)
 {
-	ipl_t v = 0;
-/*	__asm__ volatile (
-		"pushf\n\t"
-		"popl %0\n\t"
-		"cli\n"
-		: "=r" (v)
-	);*/
+	// FIXME SMP
+	
+	ipl_t v = shared_info.vcpu_info[0].evtchn_upcall_mask;
+	shared_info.vcpu_info[0].evtchn_upcall_mask = 1;
+	write_barrier();
+	
 	return v;
 }
@@ -188,9 +190,8 @@
 static inline void interrupts_restore(ipl_t ipl)
 {
-/*	__asm__ volatile (
-		"pushl %0\n\t"
-		"popf\n"
-		: : "r" (ipl)
-	);*/
+	if (ipl == 0)
+		interrupts_enable();
+	else
+		interrupts_disable();
 }
 
@@ -201,11 +202,7 @@
 static inline ipl_t interrupts_read(void)
 {
-	ipl_t v = 0;
-/*	__asm__ volatile (
-		"pushf\n\t"
-		"popl %0\n"
-		: "=r" (v)
-	);*/
-	return v;
+	// FIXME SMP
+	
+	return shared_info.vcpu_info[0].evtchn_upcall_mask;
 }
 
Index: kernel/arch/xen32/include/boot/boot.h
===================================================================
--- kernel/arch/xen32/include/boot/boot.h	(revision 7d3d641a8c852bac56e8c9ace15cfffbdf4b0173)
+++ kernel/arch/xen32/include/boot/boot.h	(revision 5b23a82c8d68ae8b01f1fbb9ace30e2377050d55)
@@ -77,5 +77,5 @@
 typedef struct {
 	uint8_t evtchn_upcall_pending;
-	uint8_t evtchn_upcall_mask;
+	ipl_t evtchn_upcall_mask;
 	evtchn_t evtchn_pending_sel;
 	arch_vcpu_info_t arch;
Index: kernel/arch/xen32/include/hypercall.h
===================================================================
--- kernel/arch/xen32/include/hypercall.h	(revision 7d3d641a8c852bac56e8c9ace15cfffbdf4b0173)
+++ kernel/arch/xen32/include/hypercall.h	(revision 5b23a82c8d68ae8b01f1fbb9ace30e2377050d55)
@@ -49,4 +49,5 @@
 #define XEN_SET_CALLBACKS		4
 #define XEN_UPDATE_VA_MAPPING	14
+#define XEN_VERSION				17
 #define XEN_CONSOLE_IO			18
 #define XEN_VM_ASSIST			21
@@ -101,4 +102,6 @@
 
 
+#define force_evtchn_callback() ((void) xen_version(0, 0))
+
 #define hypercall0(id)	\
 	({	\
@@ -219,3 +222,8 @@
 }
 
+static inline int xen_version(const unsigned int cmd, const void *arg)
+{
+	return hypercall2(XEN_VERSION, cmd, arg);
+}
+
 #endif
Index: kernel/arch/xen32/include/types.h
===================================================================
--- kernel/arch/xen32/include/types.h	(revision 7d3d641a8c852bac56e8c9ace15cfffbdf4b0173)
+++ kernel/arch/xen32/include/types.h	(revision 5b23a82c8d68ae8b01f1fbb9ace30e2377050d55)
@@ -1,1 +1,63 @@
-../../ia32/include/types.h
+/*
+ * Copyright (C) 2001-2004 Jakub Jermar
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup xen32
+ * @{
+ */
+/** @file
+ */
+
+#ifndef __TYPES_H__
+#define __TYPES_H__
+
+#define NULL 0
+
+typedef signed char int8_t;
+typedef signed short int16_t;
+typedef signed long int32_t;
+typedef signed long long int64_t;
+
+typedef unsigned char uint8_t;
+typedef unsigned short uint16_t;
+typedef unsigned long uint32_t;
+typedef unsigned long long uint64_t;
+
+typedef uint32_t uintptr_t;
+typedef uint32_t pfn_t;
+
+typedef uint8_t ipl_t;
+
+typedef uint32_t unative_t;
+typedef int32_t native_t;
+
+typedef struct page_specifier pte_t;
+
+#endif
+
+/** @}
+ */
Index: kernel/arch/xen32/src/userspace.c
===================================================================
--- kernel/arch/xen32/src/userspace.c	(revision 7d3d641a8c852bac56e8c9ace15cfffbdf4b0173)
+++ kernel/arch/xen32/src/userspace.c	(revision 5b23a82c8d68ae8b01f1fbb9ace30e2377050d55)
@@ -1,1 +1,85 @@
-../../ia32/src/userspace.c
+/*
+ * Copyright (C) 2005 Jakub Jermar
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup xen32
+ * @{
+ */
+/** @file
+ */
+
+#include <userspace.h>
+#include <arch/pm.h>
+#include <arch/types.h>
+#include <arch.h>
+#include <proc/uarg.h>
+#include <mm/as.h>
+
+
+/** Enter userspace
+ *
+ * Change CPU protection level to 3, enter userspace.
+ *
+ */
+void userspace(uspace_arg_t *kernel_uarg)
+{
+	uint32_t ipl = interrupts_disable();
+
+	asm volatile (
+		/*
+		 * Clear nested task flag.
+		 */
+		"pushfl\n"
+		"pop %%eax\n"
+		"and $0xffffbfff, %%eax\n"
+		"push %%eax\n"
+		"popfl\n"
+
+		/* Set up GS register (TLS) */
+		"movl %6, %%gs\n"
+
+		"pushl %0\n"
+		"pushl %1\n"
+		"pushl %2\n"
+		"pushl %3\n"
+		"pushl %4\n"
+		"movl %5, %%eax\n"
+		"iret\n"
+		: 
+		: "i" (selector(UDATA_DES) | PL_USER), "r" (kernel_uarg->uspace_stack+THREAD_STACK_SIZE),
+		  "r" (ipl), "i" (selector(UTEXT_DES) | PL_USER), "r" (kernel_uarg->uspace_entry),
+		"r" (kernel_uarg->uspace_uarg),
+		"r" (selector(TLS_DES))
+		: "eax");
+	
+	/* Unreachable */
+	for(;;)
+		;
+}
+
+/** @}
+ */
