Index: kernel/arch/sparc64/Makefile.inc
===================================================================
--- kernel/arch/sparc64/Makefile.inc	(revision c8ea4a8b385dcfa2947d09fcc2d484d8750d4329)
+++ kernel/arch/sparc64/Makefile.inc	(revision 32fffef00aa36a7913892cc0d7ff6eff828b2e7e)
@@ -95,4 +95,5 @@
 	arch/$(ARCH)/src/start.S \
 	arch/$(ARCH)/src/proc/scheduler.c \
+	arch/$(ARCH)/src/proc/thread.c \
 	arch/$(ARCH)/src/trap/trap_table.S \
 	arch/$(ARCH)/src/trap/trap.c \
Index: kernel/arch/sparc64/include/arch.h
===================================================================
--- kernel/arch/sparc64/include/arch.h	(revision c8ea4a8b385dcfa2947d09fcc2d484d8750d4329)
+++ kernel/arch/sparc64/include/arch.h	(revision 32fffef00aa36a7913892cc0d7ff6eff828b2e7e)
@@ -30,5 +30,7 @@
  * @{
  */
-/** @file
+/**
+ * @file
+ * @brief	Various sparc64-specific macros.
  */
 
@@ -39,7 +41,8 @@
 #define ASI_AIUS	0x11	/** Access to secondary context with user privileges. */
 
+#define NWINDOW		8	/** Number of register window sets. */
+
 #endif
 
 /** @}
  */
-
Index: kernel/arch/sparc64/include/barrier.h
===================================================================
--- kernel/arch/sparc64/include/barrier.h	(revision c8ea4a8b385dcfa2947d09fcc2d484d8750d4329)
+++ kernel/arch/sparc64/include/barrier.h	(revision 32fffef00aa36a7913892cc0d7ff6eff828b2e7e)
@@ -52,8 +52,12 @@
 	 * The FLUSH instruction takes address parameter.
 	 * As such, it may trap if the address is not found in DTLB.
-	 * However, JPS1 implementations are free to ignore the trap.
+	 *
+	 * The entire kernel text is mapped by a locked ITLB and
+	 * DTLB entries. Therefore, when this function is called,
+	 * the %o7 register will always be in the range mapped by
+	 * DTLB.
 	 */
 	 
-        __asm__ volatile ("flush %0\n" :: "r" (0x400000));
+        __asm__ volatile ("flush %o7\n");
 }
 
Index: kernel/arch/sparc64/include/proc/thread.h
===================================================================
--- kernel/arch/sparc64/include/proc/thread.h	(revision c8ea4a8b385dcfa2947d09fcc2d484d8750d4329)
+++ kernel/arch/sparc64/include/proc/thread.h	(revision 32fffef00aa36a7913892cc0d7ff6eff828b2e7e)
@@ -27,5 +27,5 @@
  */
 
- /** @addtogroup sparc64proc
+/** @addtogroup sparc64proc
  * @{
  */
@@ -33,15 +33,17 @@
  */
 
-#ifndef __sparc64_THREAD_H__
-#define __sparc64_THREAD_H__
+#ifndef KERN_sparc64_THREAD_H_
+#define KERN_sparc64_THREAD_H_
+
+#include <arch/types.h>
+#include <arch/arch.h>
 
 typedef struct {
+	/** Buffer for register windows with userspace content. */
+	uint8_t *uspace_window_buffer;
 } thread_arch_t;
-
-#define thread_create_arch(t)
 
 #endif
 
- /** @}
+/** @}
  */
-
Index: kernel/arch/sparc64/include/trap/regwin.h
===================================================================
--- kernel/arch/sparc64/include/trap/regwin.h	(revision c8ea4a8b385dcfa2947d09fcc2d484d8750d4329)
+++ kernel/arch/sparc64/include/trap/regwin.h	(revision 32fffef00aa36a7913892cc0d7ff6eff828b2e7e)
@@ -51,6 +51,4 @@
 #define FILL_HANDLER_SIZE		REGWIN_HANDLER_SIZE
 
-#define NWINDOW		8
-
 /* Window Save Area offsets. */
 #define L0_OFFSET	0
@@ -250,3 +248,2 @@
 /** @}
  */
-
Index: kernel/arch/sparc64/src/proc/thread.c
===================================================================
--- kernel/arch/sparc64/src/proc/thread.c	(revision 32fffef00aa36a7913892cc0d7ff6eff828b2e7e)
+++ kernel/arch/sparc64/src/proc/thread.c	(revision 32fffef00aa36a7913892cc0d7ff6eff828b2e7e)
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2006 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 sparc64proc
+ * @{
+ */
+/** @file
+ */
+
+#include <proc/thread.h>
+#include <arch/proc/thread.h>
+#include <mm/frame.h>
+
+void thr_constructor_arch(thread_t *t)
+{
+	/*
+	 * Allocate memory for uspace_window_buffer.
+	 */
+	t->arch.uspace_window_buffer = NULL;
+}
+
+void thr_destructor_arch(thread_t *t)
+{
+	if (t->arch.uspace_window_buffer)
+		frame_free((uintptr_t) t->arch.uspace_window_buffer);
+}
+
+void thread_create_arch(thread_t *t)
+{
+	if ((t->flags & THREAD_FLAG_USPACE) && (!t->arch.uspace_window_buffer)) {
+		/*
+		 * The thread needs userspace window buffer and the object
+		 * returned from the slab allocator doesn't have any.
+		 */
+		t->arch.uspace_window_buffer = frame_alloc(ONE_FRAME, 0);
+	}
+}
+
+/** @}
+ */
