Index: uspace/lib/libc/Makefile
===================================================================
--- uspace/lib/libc/Makefile	(revision bb54db8adf4487558f5ccf7da52b4bf5f49cd8da)
+++ uspace/lib/libc/Makefile	(revision 4d21cf8018c22aea36d3bffe12b2b30aad54c593)
@@ -51,5 +51,7 @@
 	generic/cap.c \
 	generic/string.c \
+	generic/fibril.c \
 	generic/thread.c \
+	generic/tls.c \
 	generic/task.c \
 	generic/futex.c \
@@ -64,5 +66,4 @@
 	generic/io/printf_core.c \
 	malloc/malloc.c \
-	generic/fibril.c \
 	generic/sysinfo.c \
 	generic/ipc.c \
Index: uspace/lib/libc/arch/amd64/Makefile.inc
===================================================================
--- uspace/lib/libc/arch/amd64/Makefile.inc	(revision bb54db8adf4487558f5ccf7da52b4bf5f49cd8da)
+++ uspace/lib/libc/arch/amd64/Makefile.inc	(revision 4d21cf8018c22aea36d3bffe12b2b30aad54c593)
@@ -35,5 +35,5 @@
 ARCH_SOURCES += arch/$(ARCH)/src/syscall.S \
 		arch/$(ARCH)/src/fibril.S \
-		arch/$(ARCH)/src/thread.c
+		arch/$(ARCH)/src/tls.c
 
 LFLAGS += -N
Index: uspace/lib/libc/arch/amd64/include/thread.h
===================================================================
--- uspace/lib/libc/arch/amd64/include/thread.h	(revision bb54db8adf4487558f5ccf7da52b4bf5f49cd8da)
+++ uspace/lib/libc/arch/amd64/include/thread.h	(revision 4d21cf8018c22aea36d3bffe12b2b30aad54c593)
@@ -36,24 +36,4 @@
 #define LIBC_amd64_THREAD_H_
 
-#include <libc.h>
-
-typedef struct {
-	void *self;
-	void *fibril_data;
-} tcb_t;
-
-static inline void __tcb_set(tcb_t *tcb)
-{
-	__SYSCALL1(SYS_TLS_SET, (sysarg_t) tcb);
-}
-
-static inline tcb_t * __tcb_get(void)
-{
-	void * retval;
-
-	asm ("movq %%fs:0, %0" : "=r"(retval));
-	return retval;
-}
-
 #endif
 
Index: uspace/lib/libc/arch/amd64/include/tls.h
===================================================================
--- uspace/lib/libc/arch/amd64/include/tls.h	(revision 4d21cf8018c22aea36d3bffe12b2b30aad54c593)
+++ uspace/lib/libc/arch/amd64/include/tls.h	(revision 4d21cf8018c22aea36d3bffe12b2b30aad54c593)
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2006 Ondrej Palkovsky
+ * 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 libcamd64
+ * @{
+ */
+/** @file
+ */
+
+#ifndef LIBC_amd64_TLS_H_
+#define LIBC_amd64_TLS_H_
+
+#define CONFIG_TLS_VARIANT_2
+
+#include <libc.h>
+
+typedef struct {
+	void *self;
+	void *fibril_data;
+} tcb_t;
+
+static inline void __tcb_set(tcb_t *tcb)
+{
+	__SYSCALL1(SYS_TLS_SET, (sysarg_t) tcb);
+}
+
+static inline tcb_t * __tcb_get(void)
+{
+	void * retval;
+
+	asm ("movq %%fs:0, %0" : "=r"(retval));
+	return retval;
+}
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/libc/arch/amd64/src/thread.c
===================================================================
--- uspace/lib/libc/arch/amd64/src/thread.c	(revision bb54db8adf4487558f5ccf7da52b4bf5f49cd8da)
+++ 	(revision )
@@ -1,67 +1,0 @@
-/*
- * Copyright (c) 2006 Ondrej Palkovsky
- * 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 libcamd64 amd64
- * @ingroup lc
- * @{
- */
-/** @file
-  * @ingroup libcia32
- */
-
-#include <thread.h>
-#include <malloc.h>
-#include <align.h>
-
-/** Allocate TLS & TCB for initial module threads
- *
- * @param data Start of data section
- * @return pointer to tcb_t structure
- */
-tcb_t * __alloc_tls(void **data, size_t size)
-{
-	tcb_t *tcb;
-	
-	size = ALIGN_UP(size, &_tls_alignment);
-	*data = memalign(&_tls_alignment, sizeof(tcb_t) + size);
-
-	tcb = (tcb_t *) (*data + size);
-	tcb->self = tcb;
-
-	return tcb;
-}
-
-void __free_tls_arch(tcb_t *tcb, size_t size)
-{
-	size = ALIGN_UP(size, &_tls_alignment);
-	void *start = ((void *)tcb) - size;
-	free(start);
-}
-
-/** @}
- */
Index: uspace/lib/libc/arch/amd64/src/tls.c
===================================================================
--- uspace/lib/libc/arch/amd64/src/tls.c	(revision 4d21cf8018c22aea36d3bffe12b2b30aad54c593)
+++ uspace/lib/libc/arch/amd64/src/tls.c	(revision 4d21cf8018c22aea36d3bffe12b2b30aad54c593)
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2006 Ondrej Palkovsky
+ * 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 libcamd64 amd64
+ * @ingroup lc
+ * @{
+ */
+/** @file
+  * @ingroup libcia32
+ */
+
+#include <tls.h>
+#include <sys/types.h>
+
+tcb_t * __alloc_tls(void **data, size_t size)
+{
+	return tls_alloc_variant_2(data, size);
+}
+
+void __free_tls_arch(tcb_t *tcb, size_t size)
+{
+	tls_free_variant_2(tcb, size);
+}
+
+/** @}
+ */
Index: uspace/lib/libc/arch/arm32/Makefile.inc
===================================================================
--- uspace/lib/libc/arch/arm32/Makefile.inc	(revision bb54db8adf4487558f5ccf7da52b4bf5f49cd8da)
+++ uspace/lib/libc/arch/arm32/Makefile.inc	(revision 4d21cf8018c22aea36d3bffe12b2b30aad54c593)
@@ -1,4 +1,5 @@
 #
-# Copyright (c) 2007 Michal Kebrt, Pavel Jancik
+# Copyright (c) 2007 Michal Kebrt
+# Copyright (c) 2007 Pavel Jancik
 # All rights reserved.
 #
@@ -38,5 +39,5 @@
 ARCH_SOURCES += arch/$(ARCH)/src/syscall.c \
 		arch/$(ARCH)/src/fibril.S \
-		arch/$(ARCH)/src/thread.c \
+		arch/$(ARCH)/src/tls.c \
 		arch/$(ARCH)/src/eabi.S
 
Index: uspace/lib/libc/arch/arm32/include/thread.h
===================================================================
--- uspace/lib/libc/arch/arm32/include/thread.h	(revision bb54db8adf4487558f5ccf7da52b4bf5f49cd8da)
+++ uspace/lib/libc/arch/arm32/include/thread.h	(revision 4d21cf8018c22aea36d3bffe12b2b30aad54c593)
@@ -1,4 +1,5 @@
 /*
- * Copyright (c) 2007 Pavel Jancik, Michal Kebrt
+ * Copyright (c) 2007 Pavel Jancik
+ * Copyright (c) 2007 Michal Kebrt
  * All rights reserved.
  *
@@ -31,5 +32,4 @@
  */
 /** @file
- *  @brief Uspace threads and TLS.
  */
 
@@ -37,61 +37,4 @@
 #define LIBC_arm32_THREAD_H_
 
-#include <unistd.h>
-
-/** Stack initial size. */
-#define THREAD_INITIAL_STACK_PAGES_NO 1
-
-/** Offsets for accessing __thread variables are shifted 8 bytes higher. */
-#define ARM_TP_OFFSET	(-8)
-
-/** TCB (Thread Control Block) struct. 
- *
- *  TLS starts just after this struct.
- */
-typedef struct {
-	/** Fibril data. */
-	void *fibril_data;
-} tcb_t;
-
-
-/** Sets TLS address to the r9 register.
- *
- *  @param tcb TCB (TLS starts behind)
- */
-static inline void __tcb_set(tcb_t *tcb)
-{
-	void *tls = (void *) tcb;
-	tls += sizeof(tcb_t) + ARM_TP_OFFSET;
-	asm volatile (
-		"mov r9, %0"
-		:
-		: "r"(tls)
-	);
-}
-
-
-/** Returns TCB address.
- *
- * @return TCB address (starts before TLS which address is stored in r9 register).
- */
-static inline tcb_t *__tcb_get(void)
-{
-	void *ret;
-	asm volatile (
-		"mov %0, r9"
-		: "=r"(ret)
-	);
-	return (tcb_t *) (ret - ARM_TP_OFFSET - sizeof(tcb_t));
-}
-
-
-/** Returns TLS address stored.
- *
- *  Implemented in assembly.
- *
- *  @return TLS address stored in r9 register
- */
-extern uintptr_t __aeabi_read_tp(void);
-
 #endif
 
Index: uspace/lib/libc/arch/arm32/include/tls.h
===================================================================
--- uspace/lib/libc/arch/arm32/include/tls.h	(revision 4d21cf8018c22aea36d3bffe12b2b30aad54c593)
+++ uspace/lib/libc/arch/arm32/include/tls.h	(revision 4d21cf8018c22aea36d3bffe12b2b30aad54c593)
@@ -0,0 +1,99 @@
+/*
+ * Copyright (c) 2007 Pavel Jancik
+ * Copyright (c) 2007 Michal Kebrt
+ * 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 libcarm32
+ * @{
+ */
+/** @file
+ */
+
+#ifndef LIBC_arm32_TLS_H_
+#define LIBC_arm32_TLS_H_
+
+#include <sys/types.h>
+
+#define CONFIG_TLS_VARIANT_1
+
+/** Offsets for accessing __thread variables are shifted 8 bytes higher. */
+#define ARM_TP_OFFSET  (-8)
+
+/** TCB (Thread Control Block) struct. 
+ *
+ *  TLS starts just after this struct.
+ */
+typedef struct {
+	/** Fibril data. */
+	void *fibril_data;
+} tcb_t;
+
+
+/** Sets TLS address to the r9 register.
+ *
+ *  @param tcb		TCB (TLS starts behind)
+ */
+static inline void __tcb_set(tcb_t *tcb)
+{
+	void *tls = (void *) tcb;
+	tls += sizeof(tcb_t) + ARM_TP_OFFSET;
+	asm volatile (
+		"mov r9, %0"
+		:
+		: "r" (tls)
+	);
+}
+
+
+/** Returns TCB address.
+ *
+ * @return		TCB address (starts before TLS which address is stored
+ * 			in r9 register).
+ */
+static inline tcb_t *__tcb_get(void)
+{
+	void *ret;
+	asm volatile (
+		"mov %0, r9"
+		: "=r"(ret)
+	);
+	return (tcb_t *) (ret - ARM_TP_OFFSET - sizeof(tcb_t));
+}
+
+
+/** Returns TLS address stored.
+ *
+ *  Implemented in assembly.
+ *
+ *  @return		TLS address stored in r9 register
+ */
+extern uintptr_t __aeabi_read_tp(void);
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/libc/arch/arm32/src/thread.c
===================================================================
--- uspace/lib/libc/arch/arm32/src/thread.c	(revision bb54db8adf4487558f5ccf7da52b4bf5f49cd8da)
+++ 	(revision )
@@ -1,67 +1,0 @@
-/*
- * Copyright (c) 2007 Pavel Jancik
- * 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 libcarm32 arm32
-  * @brief arm32 architecture dependent parts of libc
-  * @ingroup lc
- * @{
- */
-/** @file
- *  @brief Uspace threads and TLS.
- */
-
-#include <thread.h>
-#include <malloc.h>
-
-/** Allocates TLS & TCB.
- *
- * @param data Start of data section (output parameter).
- * @param size Size of (tbss + tdata) sections.
- * @return     Pointer to the allocated #tcb_t structure.
- */
-tcb_t * __alloc_tls(void **data, size_t size)
-{
-	tcb_t *result;
-
-	result = malloc(sizeof(tcb_t) + size);
-	*data = ((void *)result) + sizeof(tcb_t);
-	return result;
-}
-
-/** Deallocates TLS & TCB.
- *
- * @param tcb TCB structure to be deallocated (along with corresponding TLS).
- * @param size Not used.
- */
-void __free_tls_arch(tcb_t *tcb, size_t size)
-{
-	free(tcb);
-}
-
-/** @}
- */
Index: uspace/lib/libc/arch/arm32/src/tls.c
===================================================================
--- uspace/lib/libc/arch/arm32/src/tls.c	(revision 4d21cf8018c22aea36d3bffe12b2b30aad54c593)
+++ uspace/lib/libc/arch/arm32/src/tls.c	(revision 4d21cf8018c22aea36d3bffe12b2b30aad54c593)
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2007 Pavel Jancik
+ * 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 libcarm32 arm32
+  * @brief arm32 architecture dependent parts of libc
+  * @ingroup lc
+ * @{
+ */
+/** @file
+ */
+
+#include <tls.h>
+#include <sys/types.h>
+
+tcb_t * __alloc_tls(void **data, size_t size)
+{
+	return tls_alloc_variant_1(data, size);
+}
+
+void __free_tls_arch(tcb_t *tcb, size_t size)
+{
+	tls_free_variant_1(tcb, size);
+}
+
+/** @}
+ */
Index: uspace/lib/libc/arch/ia32/Makefile.inc
===================================================================
--- uspace/lib/libc/arch/ia32/Makefile.inc	(revision bb54db8adf4487558f5ccf7da52b4bf5f49cd8da)
+++ uspace/lib/libc/arch/ia32/Makefile.inc	(revision 4d21cf8018c22aea36d3bffe12b2b30aad54c593)
@@ -35,5 +35,5 @@
 ARCH_SOURCES += arch/$(ARCH)/src/syscall.c \
 		arch/$(ARCH)/src/fibril.S \
-		arch/$(ARCH)/src/thread.c
+		arch/$(ARCH)/src/tls.c
 
 LFLAGS += -N
Index: uspace/lib/libc/arch/ia32/include/thread.h
===================================================================
--- uspace/lib/libc/arch/ia32/include/thread.h	(revision bb54db8adf4487558f5ccf7da52b4bf5f49cd8da)
+++ uspace/lib/libc/arch/ia32/include/thread.h	(revision 4d21cf8018c22aea36d3bffe12b2b30aad54c593)
@@ -36,24 +36,4 @@
 #define LIBC_ia32_THREAD_H_
 
-#include <libc.h>
-
-typedef struct {
-	void *self;
-	void *fibril_data;
-} tcb_t;
-
-static inline void __tcb_set(tcb_t *tcb)
-{
-	__SYSCALL1(SYS_TLS_SET, (sysarg_t) tcb);
-}
-
-static inline tcb_t * __tcb_get(void)
-{
-	void *retval;
-
-	asm ("movl %%gs:0, %0" : "=r"(retval));
-	return retval;
-}
-
 #endif
 
Index: uspace/lib/libc/arch/ia32/include/tls.h
===================================================================
--- uspace/lib/libc/arch/ia32/include/tls.h	(revision 4d21cf8018c22aea36d3bffe12b2b30aad54c593)
+++ uspace/lib/libc/arch/ia32/include/tls.h	(revision 4d21cf8018c22aea36d3bffe12b2b30aad54c593)
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2006 Ondrej Palkovsky
+ * 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 libcia32
+ * @{
+ */
+/** @file
+ */
+
+#ifndef LIBC_ia32_TLS_H_
+#define LIBC_ia32_TLS_H_
+
+#define CONFIG_TLS_VARIANT_2
+
+#include <libc.h>
+
+typedef struct {
+	void *self;
+	void *fibril_data;
+} tcb_t;
+
+static inline void __tcb_set(tcb_t *tcb)
+{
+	__SYSCALL1(SYS_TLS_SET, (sysarg_t) tcb);
+}
+
+static inline tcb_t * __tcb_get(void)
+{
+	void *retval;
+
+	asm ("movl %%gs:0, %0" : "=r"(retval));
+	return retval;
+}
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/libc/arch/ia32/src/thread.c
===================================================================
--- uspace/lib/libc/arch/ia32/src/thread.c	(revision bb54db8adf4487558f5ccf7da52b4bf5f49cd8da)
+++ 	(revision )
@@ -1,1 +1,0 @@
-../../amd64/src/thread.c
Index: uspace/lib/libc/arch/ia32/src/tls.c
===================================================================
--- uspace/lib/libc/arch/ia32/src/tls.c	(revision 4d21cf8018c22aea36d3bffe12b2b30aad54c593)
+++ uspace/lib/libc/arch/ia32/src/tls.c	(revision 4d21cf8018c22aea36d3bffe12b2b30aad54c593)
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2006 Ondrej Palkovsky
+ * 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 libcamd64 amd64
+ * @ingroup lc
+ * @{
+ */
+/** @file
+  * @ingroup libcia32
+ */
+
+#include <tls.h>
+#include <sys/types.h>
+
+tcb_t * __alloc_tls(void **data, size_t size)
+{
+	return tls_alloc_variant_2(data, size);
+}
+
+void __free_tls_arch(tcb_t *tcb, size_t size)
+{
+	tls_free_variant_2(tcb, size);
+}
+
+/** @}
+ */
Index: uspace/lib/libc/arch/ia64/Makefile.inc
===================================================================
--- uspace/lib/libc/arch/ia64/Makefile.inc	(revision bb54db8adf4487558f5ccf7da52b4bf5f49cd8da)
+++ uspace/lib/libc/arch/ia64/Makefile.inc	(revision 4d21cf8018c22aea36d3bffe12b2b30aad54c593)
@@ -38,5 +38,5 @@
 ARCH_SOURCES += arch/$(ARCH)/src/syscall.S \
 		arch/$(ARCH)/src/fibril.S \
-		arch/$(ARCH)/src/thread.c
+		arch/$(ARCH)/src/tls.c
 
 BFD_NAME = elf64-little
Index: uspace/lib/libc/arch/ia64/include/thread.h
===================================================================
--- uspace/lib/libc/arch/ia64/include/thread.h	(revision bb54db8adf4487558f5ccf7da52b4bf5f49cd8da)
+++ uspace/lib/libc/arch/ia64/include/thread.h	(revision 4d21cf8018c22aea36d3bffe12b2b30aad54c593)
@@ -38,24 +38,4 @@
 #define THREAD_INITIAL_STACK_PAGES_NO 2
 
-/* This structure must be exactly 16 bytes long */
-typedef struct {
-	void *dtv; /* unused in static linking*/
-	void *fibril_data;
-} tcb_t;
-
-static inline void __tcb_set(tcb_t *tcb)
-{
-	asm volatile ("mov r13 = %0\n" : : "r" (tcb) : "r13");
-}
-
-static inline tcb_t *__tcb_get(void)
-{
-	void *retval;
-
-	asm volatile ("mov %0 = r13\n" : "=r" (retval));
-
-	return retval;
-}
-
 #endif
 
Index: uspace/lib/libc/arch/ia64/include/tls.h
===================================================================
--- uspace/lib/libc/arch/ia64/include/tls.h	(revision 4d21cf8018c22aea36d3bffe12b2b30aad54c593)
+++ uspace/lib/libc/arch/ia64/include/tls.h	(revision 4d21cf8018c22aea36d3bffe12b2b30aad54c593)
@@ -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 libcia64	
+ * @{
+ */
+/** @file
+ */
+
+#ifndef LIBC_ia64_TLS_H_
+#define LIBC_ia64_TLS_H_
+
+#define CONFIG_TLS_VARIANT_1
+
+#include <sys/types.h>
+
+/* This structure must be exactly 16 bytes long */
+typedef struct {
+	void *dtv; /* unused in static linking*/
+	void *fibril_data;
+} tcb_t;
+
+static inline void __tcb_set(tcb_t *tcb)
+{
+	asm volatile ("mov r13 = %0\n" : : "r" (tcb) : "r13");
+}
+
+static inline tcb_t *__tcb_get(void)
+{
+	void *retval;
+
+	asm volatile ("mov %0 = r13\n" : "=r" (retval));
+
+	return retval;
+}
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/libc/arch/ia64/src/thread.c
===================================================================
--- uspace/lib/libc/arch/ia64/src/thread.c	(revision bb54db8adf4487558f5ccf7da52b4bf5f49cd8da)
+++ 	(revision )
@@ -1,65 +1,0 @@
-/*
- * Copyright (c) 2006 Ondrej Palkovsky
- * 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 libcia64 ia64
-  * @brief ia64 architecture dependent parts of libc
-  * @ingroup lc
- * @{
- */
-/** @file
- */
-
-#include <thread.h>
-#include <malloc.h>
-
-/** Allocate TLS & TCB for initial module threads
- *
- * @param data Start of data section
- * @return pointer to tcb_t structure
- */
-extern char _tdata_start;
-extern char _tbss_end;
-tcb_t * __alloc_tls(void **data, size_t size)
-{
-	tcb_t *tcb;
-	
-/*	ASSERT(sizeof(tcb_t) == 16); */
-
-	tcb = malloc(sizeof(tcb_t) + size);
-	*data = ((void *) tcb) + 16;
-
-	return tcb;
-}
-
-void __free_tls_arch(tcb_t *tcb, size_t size)
-{
-	free(tcb);
-}
-
-/** @}
- */
Index: uspace/lib/libc/arch/ia64/src/tls.c
===================================================================
--- uspace/lib/libc/arch/ia64/src/tls.c	(revision 4d21cf8018c22aea36d3bffe12b2b30aad54c593)
+++ uspace/lib/libc/arch/ia64/src/tls.c	(revision 4d21cf8018c22aea36d3bffe12b2b30aad54c593)
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2006 Ondrej Palkovsky
+ * 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 libcia64 ia64
+  * @brief ia64 architecture dependent parts of libc
+  * @ingroup lc
+ * @{
+ */
+/** @file
+ */
+
+#include <tls.h>
+#include <malloc.h>
+
+tcb_t * __alloc_tls(void **data, size_t size)
+{
+	return tls_alloc_variant_1(data, size);
+}
+
+void __free_tls_arch(tcb_t *tcb, size_t size)
+{
+	tls_free_variant_1(tcb, size);
+}
+
+/** @}
+ */
Index: uspace/lib/libc/arch/mips32/Makefile.inc
===================================================================
--- uspace/lib/libc/arch/mips32/Makefile.inc	(revision bb54db8adf4487558f5ccf7da52b4bf5f49cd8da)
+++ uspace/lib/libc/arch/mips32/Makefile.inc	(revision 4d21cf8018c22aea36d3bffe12b2b30aad54c593)
@@ -41,5 +41,5 @@
 ARCH_SOURCES += arch/$(ARCH)/src/syscall.c \
 	arch/$(ARCH)/src/fibril.S \
-	arch/$(ARCH)/src/thread.c
+	arch/$(ARCH)/src/tls.c
 
 
Index: uspace/lib/libc/arch/mips32/include/thread.h
===================================================================
--- uspace/lib/libc/arch/mips32/include/thread.h	(revision bb54db8adf4487558f5ccf7da52b4bf5f49cd8da)
+++ uspace/lib/libc/arch/mips32/include/thread.h	(revision 4d21cf8018c22aea36d3bffe12b2b30aad54c593)
@@ -34,43 +34,6 @@
  */
 
-/* TLS for MIPS is described in http://www.linux-mips.org/wiki/NPTL */
-
 #ifndef LIBC_mips32_THREAD_H_
 #define LIBC_mips32_THREAD_H_
-
-/* I did not find any specification (neither MIPS nor PowerPC), but
- * as I found it
- * - it uses Variant II
- * - TCB is at Address(First TLS Block)+0x7000.
- * - DTV is at Address(First TLS Block)+0x8000
- * - What would happen if the TLS data was larger then 0x7000?
- * - The linker never accesses DTV directly, has the second definition any
- *   sense?
- * We will make it this way:
- * - TCB is at TP-0x7000-sizeof(tcb)
- * - No assumption about DTV etc., but it will not have a fixed address
- */
-#define MIPS_TP_OFFSET 0x7000
-
-typedef struct {
-	void *fibril_data;
-} tcb_t;
-
-static inline void __tcb_set(tcb_t *tcb)
-{
-	void *tp = tcb;
-	tp += MIPS_TP_OFFSET + sizeof(tcb_t);
-
-	asm volatile ("add $27, %0, $0" : : "r"(tp)); /* Move tls to K1 */
-}
-
-static inline tcb_t * __tcb_get(void)
-{
-	void * retval;
-
-	asm volatile("add %0, $27, $0" : "=r"(retval));
-
-	return (tcb_t *)(retval - MIPS_TP_OFFSET - sizeof(tcb_t));
-}
 
 #endif
Index: uspace/lib/libc/arch/mips32/include/tls.h
===================================================================
--- uspace/lib/libc/arch/mips32/include/tls.h	(revision 4d21cf8018c22aea36d3bffe12b2b30aad54c593)
+++ uspace/lib/libc/arch/mips32/include/tls.h	(revision 4d21cf8018c22aea36d3bffe12b2b30aad54c593)
@@ -0,0 +1,86 @@
+/*
+ * Copyright (c) 2006 Ondrej Palkovsky
+ * 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 libcmips32	
+ * @{
+ */
+/** @file
+ * @ingroup libcmips32eb	
+ */
+
+/* TLS for MIPS is described in http://www.linux-mips.org/wiki/NPTL */
+
+#ifndef LIBC_mips32_TLS_H_
+#define LIBC_mips32_TLS_H_
+
+/*
+ * FIXME: Note that the use of variant I contradicts the observations made in
+ * the note below. Nevertheless the scheme we have used for allocating and
+ * deallocatin TLS corresponds to TLS variant I.
+ */
+#define CONFIG_TLS_VARIANT_1
+
+/* I did not find any specification (neither MIPS nor PowerPC), but
+ * as I found it
+ * - it uses Variant II
+ * - TCB is at Address(First TLS Block)+0x7000.
+ * - DTV is at Address(First TLS Block)+0x8000
+ * - What would happen if the TLS data was larger then 0x7000?
+ * - The linker never accesses DTV directly, has the second definition any
+ *   sense?
+ * We will make it this way:
+ * - TCB is at TP-0x7000-sizeof(tcb)
+ * - No assumption about DTV etc., but it will not have a fixed address
+ */
+#define MIPS_TP_OFFSET 0x7000
+
+typedef struct {
+	void *fibril_data;
+} tcb_t;
+
+static inline void __tcb_set(tcb_t *tcb)
+{
+	void *tp = tcb;
+	tp += MIPS_TP_OFFSET + sizeof(tcb_t);
+
+	asm volatile ("add $27, %0, $0" : : "r"(tp)); /* Move tls to K1 */
+}
+
+static inline tcb_t * __tcb_get(void)
+{
+	void * retval;
+
+	asm volatile("add %0, $27, $0" : "=r"(retval));
+
+	return (tcb_t *)(retval - MIPS_TP_OFFSET - sizeof(tcb_t));
+}
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/libc/arch/mips32/src/thread.c
===================================================================
--- uspace/lib/libc/arch/mips32/src/thread.c	(revision bb54db8adf4487558f5ccf7da52b4bf5f49cd8da)
+++ 	(revision )
@@ -1,60 +1,0 @@
-/*
- * Copyright (c) 2006 Ondrej Palkovsky
- * 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 libcmips32	
- * @{
- */
-/** @file
- * @ingroup libcmips32eb	
- */
-
-#include <thread.h>
-#include <malloc.h>
-
-/** Allocate TLS & TCB for initial module threads
- *
- * @param data (out) Start of TLS section
- * @param size Size of tdata+tbss section
- * @return pointer to tcb_t structure
- */
-tcb_t * __alloc_tls(void **data, size_t size)
-{
-	tcb_t *result;
-
-	result = malloc(sizeof(tcb_t) + size);
-	*data = ((void *)result) + sizeof(tcb_t);
-	return result;
-}
-
-void __free_tls_arch(tcb_t *tcb, size_t size)
-{
-	free(tcb);
-}
-
-/** @}
- */
Index: uspace/lib/libc/arch/mips32/src/tls.c
===================================================================
--- uspace/lib/libc/arch/mips32/src/tls.c	(revision 4d21cf8018c22aea36d3bffe12b2b30aad54c593)
+++ uspace/lib/libc/arch/mips32/src/tls.c	(revision 4d21cf8018c22aea36d3bffe12b2b30aad54c593)
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2006 Ondrej Palkovsky
+ * 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 libcmips32	
+ * @{
+ */
+/** @file
+ * @ingroup libcmips32eb	
+ */
+
+#include <tls.h>
+#include <sys/types.h>
+
+tcb_t * __alloc_tls(void **data, size_t size)
+{
+	return tls_alloc_variant_1(data, size);
+}
+
+void __free_tls_arch(tcb_t *tcb, size_t size)
+{
+	tls_free_variant_1(tcb, size);
+}
+
+/** @}
+ */
Index: uspace/lib/libc/arch/mips32eb/Makefile.inc
===================================================================
--- uspace/lib/libc/arch/mips32eb/Makefile.inc	(revision bb54db8adf4487558f5ccf7da52b4bf5f49cd8da)
+++ uspace/lib/libc/arch/mips32eb/Makefile.inc	(revision 4d21cf8018c22aea36d3bffe12b2b30aad54c593)
@@ -36,5 +36,5 @@
 ARCH_SOURCES += arch/$(ARCH)/src/syscall.c \
 		arch/$(ARCH)/src/fibril.S \
-		arch/$(ARCH)/src/thread.c
+		arch/$(ARCH)/src/tls.c
 
 LFLAGS += -N
Index: uspace/lib/libc/arch/mips32eb/include/tls.h
===================================================================
--- uspace/lib/libc/arch/mips32eb/include/tls.h	(revision 4d21cf8018c22aea36d3bffe12b2b30aad54c593)
+++ uspace/lib/libc/arch/mips32eb/include/tls.h	(revision 4d21cf8018c22aea36d3bffe12b2b30aad54c593)
@@ -0,0 +1,1 @@
+../../mips32/include/tls.h
Index: uspace/lib/libc/arch/ppc32/Makefile.inc
===================================================================
--- uspace/lib/libc/arch/ppc32/Makefile.inc	(revision bb54db8adf4487558f5ccf7da52b4bf5f49cd8da)
+++ uspace/lib/libc/arch/ppc32/Makefile.inc	(revision 4d21cf8018c22aea36d3bffe12b2b30aad54c593)
@@ -35,5 +35,5 @@
 ARCH_SOURCES += arch/$(ARCH)/src/syscall.c \
 		arch/$(ARCH)/src/fibril.S \
-		arch/$(ARCH)/src/thread.c
+		arch/$(ARCH)/src/tls.c
 
 CFLAGS += -mcpu=powerpc -msoft-float -m32
Index: uspace/lib/libc/arch/ppc32/include/thread.h
===================================================================
--- uspace/lib/libc/arch/ppc32/include/thread.h	(revision bb54db8adf4487558f5ccf7da52b4bf5f49cd8da)
+++ uspace/lib/libc/arch/ppc32/include/thread.h	(revision 4d21cf8018c22aea36d3bffe12b2b30aad54c593)
@@ -36,34 +36,4 @@
 #define LIBC_ppc32_THREAD_H_
 
-#define PPC_TP_OFFSET 0x7000
-
-typedef struct {
-	void *fibril_data;
-} tcb_t;
-
-static inline void __tcb_set(tcb_t *tcb)
-{
-	void *tp = tcb;
-	tp += PPC_TP_OFFSET + sizeof(tcb_t);
-	
-	asm volatile (
-		"mr %%r2, %0\n"
-		:
-		: "r" (tp)
-	);
-}
-
-static inline tcb_t * __tcb_get(void)
-{
-	void * retval;
-	
-	asm volatile (
-		"mr %0, %%r2\n"
-		: "=r" (retval)
-	);
-
-	return (tcb_t *)(retval - PPC_TP_OFFSET - sizeof(tcb_t));
-}
-
 #endif
 
Index: uspace/lib/libc/arch/ppc32/include/tls.h
===================================================================
--- uspace/lib/libc/arch/ppc32/include/tls.h	(revision 4d21cf8018c22aea36d3bffe12b2b30aad54c593)
+++ uspace/lib/libc/arch/ppc32/include/tls.h	(revision 4d21cf8018c22aea36d3bffe12b2b30aad54c593)
@@ -0,0 +1,73 @@
+/*
+ * Copyright (c) 2006 Martin Decky
+ * 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 libcppc32	
+ * @{
+ */
+/** @file
+ */
+
+#ifndef LIBC_ppc32_TLS_H_
+#define LIBC_ppc32_TLS_H_
+
+#define CONFIG_TLS_VARIANT_1
+
+#define PPC_TP_OFFSET 0x7000
+
+typedef struct {
+	void *fibril_data;
+} tcb_t;
+
+static inline void __tcb_set(tcb_t *tcb)
+{
+	void *tp = tcb;
+	tp += PPC_TP_OFFSET + sizeof(tcb_t);
+	
+	asm volatile (
+		"mr %%r2, %0\n"
+		:
+		: "r" (tp)
+	);
+}
+
+static inline tcb_t * __tcb_get(void)
+{
+	void * retval;
+	
+	asm volatile (
+		"mr %0, %%r2\n"
+		: "=r" (retval)
+	);
+
+	return (tcb_t *)(retval - PPC_TP_OFFSET - sizeof(tcb_t));
+}
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/libc/arch/ppc32/src/thread.c
===================================================================
--- uspace/lib/libc/arch/ppc32/src/thread.c	(revision bb54db8adf4487558f5ccf7da52b4bf5f49cd8da)
+++ 	(revision )
@@ -1,59 +1,0 @@
-/*
- * Copyright (c) 2006 Ondrej Palkovsky
- * 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 libcppc32	
- * @{
- */
-/** @file
- */
-
-#include <thread.h>
-#include <malloc.h>
-
-/** Allocate TLS & TCB for initial module threads
- *
- * @param data Start of data section
- * @return pointer to tcb_t structure
- *
- */
-tcb_t * __alloc_tls(void **data, size_t size)
-{
-	tcb_t *result;
-
-	result = malloc(sizeof(tcb_t) + size);
-	*data = ((void *)result) + sizeof(tcb_t);
-	return result;
-}
-
-void __free_tls_arch(tcb_t *tcb, size_t size)
-{
-	free(tcb);
-}
-
-/** @}
- */
Index: uspace/lib/libc/arch/ppc32/src/tls.c
===================================================================
--- uspace/lib/libc/arch/ppc32/src/tls.c	(revision 4d21cf8018c22aea36d3bffe12b2b30aad54c593)
+++ uspace/lib/libc/arch/ppc32/src/tls.c	(revision 4d21cf8018c22aea36d3bffe12b2b30aad54c593)
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2006 Ondrej Palkovsky
+ * 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 libcppc32	
+ * @{
+ */
+/** @file
+ */
+
+#include <tls.h>
+#include <sys/types.h>
+
+tcb_t * __alloc_tls(void **data, size_t size)
+{
+	return tls_alloc_variant_1(data, size);
+}
+
+void __free_tls_arch(tcb_t *tcb, size_t size)
+{
+	tls_free_variant_1(tcb, size);
+}
+
+/** @}
+ */
Index: uspace/lib/libc/arch/ppc64/Makefile.inc
===================================================================
--- uspace/lib/libc/arch/ppc64/Makefile.inc	(revision bb54db8adf4487558f5ccf7da52b4bf5f49cd8da)
+++ uspace/lib/libc/arch/ppc64/Makefile.inc	(revision 4d21cf8018c22aea36d3bffe12b2b30aad54c593)
@@ -35,5 +35,5 @@
 ARCH_SOURCES += arch/$(ARCH)/src/syscall.c \
 		arch/$(ARCH)/src/fibril.S \
-		arch/$(ARCH)/src/thread.c
+		arch/$(ARCH)/src/tls.c
 
 CFLAGS += -mcpu=powerpc64 -msoft-float -m64
Index: uspace/lib/libc/arch/ppc64/include/thread.h
===================================================================
--- uspace/lib/libc/arch/ppc64/include/thread.h	(revision bb54db8adf4487558f5ccf7da52b4bf5f49cd8da)
+++ uspace/lib/libc/arch/ppc64/include/thread.h	(revision 4d21cf8018c22aea36d3bffe12b2b30aad54c593)
@@ -36,34 +36,4 @@
 #define LIBC_ppc64_THREAD_H_
 
-#define PPC_TP_OFFSET 0x7000
-
-typedef struct {
-	void *fibril_data;
-} tcb_t;
-
-static inline void __tcb_set(tcb_t *tcb)
-{
-	void *tp = tcb;
-	tp += PPC_TP_OFFSET + sizeof(tcb_t);
-	
-	asm volatile (
-		"mr %%r2, %0\n"
-		:
-		: "r" (tp)
-	);
-}
-
-static inline tcb_t * __tcb_get(void)
-{
-	void * retval;
-	
-	asm volatile (
-		"mr %0, %%r2\n"
-		: "=r" (retval)
-	);
-
-	return (tcb_t *)(retval - PPC_TP_OFFSET - sizeof(tcb_t));
-}
-
 #endif
 
Index: uspace/lib/libc/arch/ppc64/include/tls.h
===================================================================
--- uspace/lib/libc/arch/ppc64/include/tls.h	(revision 4d21cf8018c22aea36d3bffe12b2b30aad54c593)
+++ uspace/lib/libc/arch/ppc64/include/tls.h	(revision 4d21cf8018c22aea36d3bffe12b2b30aad54c593)
@@ -0,0 +1,73 @@
+/*
+ * Copyright (c) 2006 Martin Decky
+ * 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 libcppc64	
+ * @{
+ */
+/** @file
+ */
+
+#ifndef LIBC_ppc64_TLS_H_
+#define LIBC_ppc64_TLS_H_
+
+#define CONFIG_TLS_VARIANT_1
+
+#define PPC_TP_OFFSET 0x7000
+
+typedef struct {
+	void *fibril_data;
+} tcb_t;
+
+static inline void __tcb_set(tcb_t *tcb)
+{
+	void *tp = tcb;
+	tp += PPC_TP_OFFSET + sizeof(tcb_t);
+	
+	asm volatile (
+		"mr %%r2, %0\n"
+		:
+		: "r" (tp)
+	);
+}
+
+static inline tcb_t * __tcb_get(void)
+{
+	void * retval;
+	
+	asm volatile (
+		"mr %0, %%r2\n"
+		: "=r" (retval)
+	);
+
+	return (tcb_t *)(retval - PPC_TP_OFFSET - sizeof(tcb_t));
+}
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/libc/arch/ppc64/src/thread.c
===================================================================
--- uspace/lib/libc/arch/ppc64/src/thread.c	(revision bb54db8adf4487558f5ccf7da52b4bf5f49cd8da)
+++ 	(revision )
@@ -1,60 +1,0 @@
-/*
- * Copyright (c) 2006 Ondrej Palkovsky
- * 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 libcppc64	
- * @{
- */
-/** @file
- */
-
-#include <thread.h>
-#include <malloc.h>
-
-/** Allocate TLS & TCB for initial module threads
- *
- * @param data Start of data section
- * @return pointer to tcb_t structure
- *
- */
-tcb_t * __alloc_tls(void **data, size_t size)
-{
-	tcb_t *tcb;
-	
-	*data = malloc(sizeof(tcb_t) + size);
-	tcb = (tcb_t *) (*data + size);
-	return tcb;
-}
-
-void __free_tls_arch(tcb_t *tcb, size_t size)
-{
-	void *start = ((void *) tcb) - size;
-	free(start);
-}
-
-/** @}
- */
Index: uspace/lib/libc/arch/ppc64/src/tls.c
===================================================================
--- uspace/lib/libc/arch/ppc64/src/tls.c	(revision 4d21cf8018c22aea36d3bffe12b2b30aad54c593)
+++ uspace/lib/libc/arch/ppc64/src/tls.c	(revision 4d21cf8018c22aea36d3bffe12b2b30aad54c593)
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2006 Ondrej Palkovsky
+ * 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 libcppc64	
+ * @{
+ */
+/** @file
+ */
+
+#include <thread.h>
+#include <malloc.h>
+
+/** Allocate TLS & TCB for initial module threads
+ *
+ * @param data Start of data section
+ * @return pointer to tcb_t structure
+ *
+ */
+tcb_t * __alloc_tls(void **data, size_t size)
+{
+	tcb_t *tcb;
+	
+	*data = malloc(sizeof(tcb_t) + size);
+	tcb = (tcb_t *) (*data + size);
+	return tcb;
+}
+
+void __free_tls_arch(tcb_t *tcb, size_t size)
+{
+	void *start = ((void *) tcb) - size;
+	free(start);
+}
+
+/** @}
+ */
Index: uspace/lib/libc/arch/sparc64/Makefile.inc
===================================================================
--- uspace/lib/libc/arch/sparc64/Makefile.inc	(revision bb54db8adf4487558f5ccf7da52b4bf5f49cd8da)
+++ uspace/lib/libc/arch/sparc64/Makefile.inc	(revision 4d21cf8018c22aea36d3bffe12b2b30aad54c593)
@@ -34,5 +34,5 @@
 
 ARCH_SOURCES += arch/$(ARCH)/src/fibril.S \
-		arch/$(ARCH)/src/thread.c
+		arch/$(ARCH)/src/tls.c
 
 CFLAGS += -mcpu=ultrasparc -m64
Index: uspace/lib/libc/arch/sparc64/include/thread.h
===================================================================
--- uspace/lib/libc/arch/sparc64/include/thread.h	(revision bb54db8adf4487558f5ccf7da52b4bf5f49cd8da)
+++ uspace/lib/libc/arch/sparc64/include/thread.h	(revision 4d21cf8018c22aea36d3bffe12b2b30aad54c593)
@@ -31,30 +31,7 @@
  * @{
  */
-/**
- * @file
- * @brief	sparc64 TLS functions.
- */
 
 #ifndef LIBC_sparc64_THREAD_H_
 #define LIBC_sparc64_THREAD_H_
-
-typedef struct {
-	void *self;
-	void *fibril_data;
-} tcb_t;
-
-static inline void __tcb_set(tcb_t *tcb)
-{
-	asm volatile ("mov %0, %%g7\n" : : "r" (tcb) : "g7");
-}
-
-static inline tcb_t * __tcb_get(void)
-{
-	void *retval;
-
-	asm volatile ("mov %%g7, %0\n" : "=r" (retval));
-
-	return retval;
-}
 
 #endif
Index: uspace/lib/libc/arch/sparc64/include/tls.h
===================================================================
--- uspace/lib/libc/arch/sparc64/include/tls.h	(revision 4d21cf8018c22aea36d3bffe12b2b30aad54c593)
+++ uspace/lib/libc/arch/sparc64/include/tls.h	(revision 4d21cf8018c22aea36d3bffe12b2b30aad54c593)
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2006 Ondrej Palkovsky
+ * 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 libcsparc64
+ * @{
+ */
+/**
+ * @file
+ * @brief	sparc64 TLS functions.
+ */
+
+#ifndef LIBC_sparc64_TLS_H_
+#define LIBC_sparc64_TLS_H_
+
+#define CONFIG_TLS_VARIANT_2
+
+typedef struct {
+	void *self;
+	void *fibril_data;
+} tcb_t;
+
+static inline void __tcb_set(tcb_t *tcb)
+{
+	asm volatile ("mov %0, %%g7\n" : : "r" (tcb) : "g7");
+}
+
+static inline tcb_t * __tcb_get(void)
+{
+	void *retval;
+
+	asm volatile ("mov %%g7, %0\n" : "=r" (retval));
+
+	return retval;
+}
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/libc/arch/sparc64/src/thread.c
===================================================================
--- uspace/lib/libc/arch/sparc64/src/thread.c	(revision bb54db8adf4487558f5ccf7da52b4bf5f49cd8da)
+++ 	(revision )
@@ -1,84 +1,0 @@
-/*
- * Copyright (c) 2006 Ondrej Palkovsky
- * 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 libcsparc64 sparc64
- * @ingroup lc
- * @{
- */
-/** @file
- *
- */
-
-#include <thread.h>
-#include <malloc.h>
-#include <align.h>
-
-/*
- * sparc64 uses thread-local storage data structures, variant II, as described
- * in:
- * 	Drepper U.: ELF Handling For Thread-Local Storage, 2005
- */
-
-/** Allocate TLS variant II data structures for a thread.
- *
- * Only static model is supported.
- *
- * @param data Pointer to pointer to thread local data. This is actually an
- * 	output argument.
- * @param size Size of thread local data.
- * @return Pointer to TCB structure.
- */
-tcb_t * __alloc_tls(void **data, size_t size)
-{
-	tcb_t *tcb;
-	
-	size = ALIGN_UP(size, &_tls_alignment);
-	*data = memalign(&_tls_alignment, sizeof(tcb_t) + size);
-
-	tcb = (tcb_t *) (*data + size);
-	tcb->self = tcb;
-
-	return tcb;
-}
-
-/** Free TLS variant II data structures of a thread.
- *
- * Only static model is supported.
- *
- * @param tcb Pointer to TCB structure.
- * @param size Size of thread local data.
- */
-void __free_tls_arch(tcb_t *tcb, size_t size)
-{
-	size = ALIGN_UP(size, &_tls_alignment);
-	void *start = ((void *) tcb) - size;
-	free(start);
-}
-
-/** @}
- */
Index: uspace/lib/libc/arch/sparc64/src/tls.c
===================================================================
--- uspace/lib/libc/arch/sparc64/src/tls.c	(revision 4d21cf8018c22aea36d3bffe12b2b30aad54c593)
+++ uspace/lib/libc/arch/sparc64/src/tls.c	(revision 4d21cf8018c22aea36d3bffe12b2b30aad54c593)
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2006 Ondrej Palkovsky
+ * 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 libcsparc64 sparc64
+ * @ingroup lc
+ * @{
+ */
+/** @file
+ *
+ */
+
+#include <tls.h>
+#include <sys/types.h>
+
+tcb_t * __alloc_tls(void **data, size_t size)
+{
+	return tls_alloc_variant_2(data, size);
+}
+
+void __free_tls_arch(tcb_t *tcb, size_t size)
+{
+	tls_free_variant_2(tcb, size);
+}
+
+/** @}
+ */
Index: uspace/lib/libc/generic/fibril.c
===================================================================
--- uspace/lib/libc/generic/fibril.c	(revision bb54db8adf4487558f5ccf7da52b4bf5f49cd8da)
+++ uspace/lib/libc/generic/fibril.c	(revision 4d21cf8018c22aea36d3bffe12b2b30aad54c593)
@@ -36,7 +36,8 @@
 #include <libadt/list.h>
 #include <fibril.h>
+#include <thread.h>
+#include <tls.h>
 #include <malloc.h>
 #include <unistd.h>
-#include <thread.h>
 #include <stdio.h>
 #include <libarch/faddr.h>
Index: uspace/lib/libc/generic/libc.c
===================================================================
--- uspace/lib/libc/generic/libc.c	(revision bb54db8adf4487558f5ccf7da52b4bf5f49cd8da)
+++ uspace/lib/libc/generic/libc.c	(revision 4d21cf8018c22aea36d3bffe12b2b30aad54c593)
@@ -41,6 +41,7 @@
 #include <libc.h>
 #include <unistd.h>
+#include <malloc.h>
+#include <tls.h>
 #include <thread.h>
-#include <malloc.h>
 #include <fibril.h>
 #include <io/stream.h>
Index: uspace/lib/libc/generic/thread.c
===================================================================
--- uspace/lib/libc/generic/thread.c	(revision bb54db8adf4487558f5ccf7da52b4bf5f49cd8da)
+++ uspace/lib/libc/generic/thread.c	(revision 4d21cf8018c22aea36d3bffe12b2b30aad54c593)
@@ -42,51 +42,7 @@
 #include <async.h>
 
-#include <stdio.h>
-
-
 #ifndef THREAD_INITIAL_STACK_PAGES_NO
 #define THREAD_INITIAL_STACK_PAGES_NO 1
 #endif
-
-static LIST_INITIALIZE(thread_garbage);
-
-extern char _tdata_start;
-extern char _tdata_end;
-extern char _tbss_start;
-extern char _tbss_end;
-
-/** Create TLS (Thread Local Storage) data structures.
- *
- * The code requires, that sections .tdata and .tbss are adjacent. It may be
- * changed in the future.
- *
- * @return Pointer to TCB.
- */
-tcb_t *__make_tls(void)
-{
-	void *data;
-	tcb_t *tcb;
-	size_t tls_size = &_tbss_end - &_tdata_start;
-	
-	tcb = __alloc_tls(&data, tls_size);
-	
-	/*
-	 * Copy thread local data from the initialization image.
-	 */
-	memcpy(data, &_tdata_start, &_tdata_end - &_tdata_start);
-	/*
-	 * Zero out the thread local uninitialized data.
-	 */
-	memset(data + (&_tbss_start - &_tdata_start), 0,
-	    &_tbss_end - &_tbss_start);
-
-	return tcb;
-}
-
-void __free_tls(tcb_t *tcb)
-{
-	size_t tls_size = &_tbss_end - &_tdata_start;
-	__free_tls_arch(tcb, tls_size);
-}
 
 /** Main thread function.
Index: uspace/lib/libc/generic/tls.c
===================================================================
--- uspace/lib/libc/generic/tls.c	(revision 4d21cf8018c22aea36d3bffe12b2b30aad54c593)
+++ uspace/lib/libc/generic/tls.c	(revision 4d21cf8018c22aea36d3bffe12b2b30aad54c593)
@@ -0,0 +1,141 @@
+/*
+ * 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 libc
+ * @{
+ */
+/** @file
+ *
+ * Support for thread-local storage, as described in:
+ * 	Drepper U.: ELF Handling For Thread-Local Storage, 2005
+ *
+ * Only static model is supported.
+ */ 
+
+#include <tls.h>
+#include <malloc.h>
+#include <string.h>
+#include <align.h>
+
+/** Create TLS (Thread Local Storage) data structures.
+ *
+ * The code requires, that sections .tdata and .tbss are adjacent. It may be
+ * changed in the future.
+ *
+ * @return Pointer to TCB.
+ */
+tcb_t *__make_tls(void)
+{
+	void *data;
+	tcb_t *tcb;
+	size_t tls_size = &_tbss_end - &_tdata_start;
+	
+	tcb = __alloc_tls(&data, tls_size);
+	
+	/*
+	 * Copy thread local data from the initialization image.
+	 */
+	memcpy(data, &_tdata_start, &_tdata_end - &_tdata_start);
+	/*
+	 * Zero out the thread local uninitialized data.
+	 */
+	memset(data + (&_tbss_start - &_tdata_start), 0,
+	    &_tbss_end - &_tbss_start);
+
+	return tcb;
+}
+
+void __free_tls(tcb_t *tcb)
+{
+	size_t tls_size = &_tbss_end - &_tdata_start;
+	__free_tls_arch(tcb, tls_size);
+}
+
+#ifdef CONFIG_TLS_VARIANT_1
+/** Allocate TLS variant 1 data structures.
+ *
+ * @param data 		Start of TLS section. This is an output argument.
+ * @param size		Size of tdata + tbss section.
+ * @return 		Pointer to tcb_t structure.
+ */
+tcb_t *tls_alloc_variant_1(void **data, size_t size)
+{
+	tcb_t *result;
+
+	result = malloc(sizeof(tcb_t) + size);
+	*data = ((void *)result) + sizeof(tcb_t);
+	return result;
+}
+
+/** Free TLS variant I data structures.
+ *
+ * @param tcb		Pointer to TCB structure.
+ * @param size		This argument is ignored.
+ */
+void tls_free_variant_1(tcb_t *tcb, size_t size)
+{
+	free(tcb);
+}
+#endif
+
+#ifdef CONFIG_TLS_VARIANT_2
+/** Allocate TLS variant II data structures.
+ *
+ * @param data		Pointer to pointer to thread local data. This is
+ * 			actually an output argument.
+ * @param size		Size of thread local data.
+ * @return		Pointer to TCB structure.
+ */
+tcb_t * tls_alloc_variant_2(void **data, size_t size)
+{
+	tcb_t *tcb;
+	
+	size = ALIGN_UP(size, &_tls_alignment);
+	*data = memalign(&_tls_alignment, sizeof(tcb_t) + size);
+
+	tcb = (tcb_t *) (*data + size);
+	tcb->self = tcb;
+
+	return tcb;
+}
+
+/** Free TLS variant II data structures.
+ *
+ * @param tcb		Pointer to TCB structure.
+ * @param size		Size of thread local data.
+ */
+void tls_free_variant_2(tcb_t *tcb, size_t size)
+{
+	size = ALIGN_UP(size, &_tls_alignment);
+	void *start = ((void *) tcb) - size;
+	free(start);
+}
+#endif
+
+/** @}
+ */
Index: uspace/lib/libc/include/fibril.h
===================================================================
--- uspace/lib/libc/include/fibril.h	(revision bb54db8adf4487558f5ccf7da52b4bf5f49cd8da)
+++ uspace/lib/libc/include/fibril.h	(revision 4d21cf8018c22aea36d3bffe12b2b30aad54c593)
@@ -38,5 +38,5 @@
 #include <libarch/fibril.h>
 #include <libadt/list.h>
-#include <libarch/thread.h>
+#include <libarch/tls.h>
 
 #ifndef context_set
Index: uspace/lib/libc/include/thread.h
===================================================================
--- uspace/lib/libc/include/thread.h	(revision bb54db8adf4487558f5ccf7da52b4bf5f49cd8da)
+++ uspace/lib/libc/include/thread.h	(revision 4d21cf8018c22aea36d3bffe12b2b30aad54c593)
@@ -42,18 +42,12 @@
 typedef uint64_t thread_id_t;
 
-extern char _tls_alignment;
+extern void __thread_entry(void);
+extern void __thread_main(uspace_arg_t *);
 
-extern void __thread_entry(void);
-extern void __thread_main(uspace_arg_t *uarg);
-
-extern int thread_create(void (* function)(void *), void *arg, char *name, thread_id_t *tid);
-extern void thread_exit(int status);
-extern void thread_detach(thread_id_t thread);
-extern int thread_join(thread_id_t thread);
+extern int thread_create(void (*)(void *), void *, char *, thread_id_t *);
+extern void thread_exit(int);
+extern void thread_detach(thread_id_t);
+extern int thread_join(thread_id_t);
 extern thread_id_t thread_get_id(void);
-extern tcb_t * __make_tls(void);
-extern tcb_t * __alloc_tls(void **data, size_t size);
-extern void __free_tls(tcb_t *);
-extern void __free_tls_arch(tcb_t *, size_t size);
 
 #endif
Index: uspace/lib/libc/include/tls.h
===================================================================
--- uspace/lib/libc/include/tls.h	(revision 4d21cf8018c22aea36d3bffe12b2b30aad54c593)
+++ uspace/lib/libc/include/tls.h	(revision 4d21cf8018c22aea36d3bffe12b2b30aad54c593)
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2007 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 libc
+ * @{
+ */
+/** @file
+ */
+
+#ifndef LIBC_TLS_H_
+#define LIBC_TLS_H_
+
+#include <libarch/tls.h>
+#include <sys/types.h>
+
+/*
+ * Symbols defined in the respective linker script.
+ */
+extern char _tls_alignment;
+extern char _tdata_start;
+extern char _tdata_end;
+extern char _tbss_start;
+extern char _tbss_end;
+
+extern tcb_t *__make_tls(void);
+extern tcb_t *__alloc_tls(void **, size_t);
+extern void __free_tls(tcb_t *);
+extern void __free_tls_arch(tcb_t *, size_t);
+
+#ifdef CONFIG_TLS_VARIANT_1
+extern tcb_t *tls_alloc_variant_1(void **, size_t);
+extern void tls_free_variant_1(tcb_t *, size_t);
+#endif
+#ifdef CONFIG_TLS_VARIANT_2
+extern tcb_t *tls_alloc_variant_2(void **, size_t);
+extern void tls_free_variant_2(tcb_t *, size_t);
+#endif
+
+#endif
+
+/** @}
+ */
