Index: kernel/Makefile
===================================================================
--- kernel/Makefile	(revision 0747468d84f2b1c59f16a0b00b33c12aa2a95e3f)
+++ kernel/Makefile	(revision 97c76825acca82d15cb8daa0e50df4f66ffd6c0b)
@@ -103,8 +103,4 @@
 	-Werror-implicit-function-declaration -wd170
 
-SUNCC_CFLAGS = -I$(INCLUDES) -xO$(OPTIMIZATION) \
-	-xnolib -xc99=all -features=extensions \
-	-erroff=E_ZERO_SIZED_STRUCT_UNION
-
 CLANG_CFLAGS = -I$(INCLUDES) -O$(OPTIMIZATION) -imacros $(CONFIG_HEADER) \
 	-fexec-charset=UTF-8 -fwide-exec-charset=UTF-32$(ENDIANESS) \
@@ -126,5 +122,4 @@
 	GCC_CFLAGS += -g
 	ICC_CFLAGS += -g
-	SUNCC_CFLAGS += -g
 	CLANG_CFLAGS += -g
 endif
@@ -180,11 +175,4 @@
 	CFLAGS = $(ICC_CFLAGS)
 	DEPEND_DEFS = $(DEFS) $(CONFIG_DEFS)
-	INSTRUMENTATION =
-endif
-
-ifeq ($(COMPILER),suncc)
-	CFLAGS = $(SUNCC_CFLAGS)
-	DEFS += $(CONFIG_DEFS)
-	DEPEND_DEFS = $(DEFS)
 	INSTRUMENTATION =
 endif
@@ -208,4 +196,5 @@
 	generic/src/console/chardev.c \
 	generic/src/console/console.c \
+	generic/src/console/prompt.c \
 	generic/src/cpu/cpu.c \
 	generic/src/ddi/ddi.c \
Index: kernel/arch/abs32le/include/mm/page.h
===================================================================
--- kernel/arch/abs32le/include/mm/page.h	(revision 0747468d84f2b1c59f16a0b00b33c12aa2a95e3f)
+++ kernel/arch/abs32le/include/mm/page.h	(revision 97c76825acca82d15cb8daa0e50df4f66ffd6c0b)
@@ -105,4 +105,12 @@
 	set_pt_flags((pte_t *) (ptl3), (size_t) (i), (x))
 
+/* Set PTE present bit accessors for each level. */
+#define SET_PTL1_PRESENT_ARCH(ptl0, i)	\
+	set_pt_present((pte_t *) (ptl0), (size_t) (i))
+#define SET_PTL2_PRESENT_ARCH(ptl1, i)
+#define SET_PTL3_PRESENT_ARCH(ptl2, i)
+#define SET_FRAME_PRESENT_ARCH(ptl3, i) \
+	set_pt_present((pte_t *) (ptl3), (size_t) (i))
+
 /* Macros for querying the last level entries. */
 #define PTE_VALID_ARCH(p) \
@@ -173,4 +181,13 @@
 }
 
+NO_TRACE static inline void set_pt_present(pte_t *pt, size_t i)
+    WRITES(ARRAY_RANGE(pt, PTL0_ENTRIES_ARCH))
+    REQUIRES_ARRAY_MUTABLE(pt, PTL0_ENTRIES_ARCH)
+{
+	pte_t *p = &pt[i];
+
+	p->present = 1;
+}
+
 extern void page_arch_init(void);
 extern void page_fault(unsigned int, istate_t *);
Index: kernel/arch/amd64/Makefile.inc
===================================================================
--- kernel/arch/amd64/Makefile.inc	(revision 0747468d84f2b1c59f16a0b00b33c12aa2a95e3f)
+++ kernel/arch/amd64/Makefile.inc	(revision 97c76825acca82d15cb8daa0e50df4f66ffd6c0b)
@@ -55,5 +55,4 @@
 GCC_CFLAGS += $(CMN1)
 ICC_CFLAGS += $(CMN1)
-SUNCC_CFLAGS += -m64 -xmodel=kernel
 
 BITS = 64
@@ -67,5 +66,4 @@
 	GCC_CFLAGS += $(CMN2)
 	ICC_CFLAGS += $(CMN2)
-	SUNCC_CFLAGS += -xtarget=opteron
 endif
 
Index: kernel/arch/amd64/include/mm/page.h
===================================================================
--- kernel/arch/amd64/include/mm/page.h	(revision 0747468d84f2b1c59f16a0b00b33c12aa2a95e3f)
+++ kernel/arch/amd64/include/mm/page.h	(revision 97c76825acca82d15cb8daa0e50df4f66ffd6c0b)
@@ -33,13 +33,4 @@
  */
 
-/** Paging on AMD64
- *
- * The space is divided in positive numbers (uspace) and
- * negative numbers (kernel). The 'negative' space starting
- * with 0xffff800000000000 and ending with 0xffffffffffffffff
- * is identically mapped physical memory.
- *
- */
-
 #ifndef KERN_amd64_PAGE_H_
 #define KERN_amd64_PAGE_H_
@@ -127,4 +118,14 @@
 #define SET_FRAME_FLAGS_ARCH(ptl3, i, x) \
 	set_pt_flags((pte_t *) (ptl3), (size_t) (i), (x))
+
+/* Set PTE present bit accessors for each level. */
+#define SET_PTL1_PRESENT_ARCH(ptl0, i) \
+	set_pt_present((pte_t *) (ptl0), (size_t) (i))
+#define SET_PTL2_PRESENT_ARCH(ptl1, i) \
+	set_pt_present((pte_t *) (ptl1), (size_t) (i))
+#define SET_PTL3_PRESENT_ARCH(ptl2, i) \
+	set_pt_present((pte_t *) (ptl2), (size_t) (i))
+#define SET_FRAME_PRESENT_ARCH(ptl3, i) \
+	set_pt_present((pte_t *) (ptl3), (size_t) (i))
 
 /* Macros for querying the last-level PTE entries. */
@@ -224,4 +225,11 @@
 }
 
+NO_TRACE static inline void set_pt_present(pte_t *pt, size_t i)
+{
+	pte_t *p = &pt[i];
+
+	p->present = 1;
+}
+
 extern void page_arch_init(void);
 extern void page_fault(unsigned int, istate_t *);
Index: kernel/arch/amd64/src/mm/page.c
===================================================================
--- kernel/arch/amd64/src/mm/page.c	(revision 0747468d84f2b1c59f16a0b00b33c12aa2a95e3f)
+++ kernel/arch/amd64/src/mm/page.c	(revision 97c76825acca82d15cb8daa0e50df4f66ffd6c0b)
@@ -57,5 +57,5 @@
 	uintptr_t cur;
 	unsigned int identity_flags =
-	    PAGE_CACHEABLE | PAGE_EXEC | PAGE_GLOBAL | PAGE_WRITE;
+	    PAGE_GLOBAL | PAGE_CACHEABLE | PAGE_EXEC | PAGE_WRITE | PAGE_READ;
 		
 	page_mapping_operations = &pt_mapping_operations;
Index: kernel/arch/amd64/src/userspace.c
===================================================================
--- kernel/arch/amd64/src/userspace.c	(revision 0747468d84f2b1c59f16a0b00b33c12aa2a95e3f)
+++ kernel/arch/amd64/src/userspace.c	(revision 97c76825acca82d15cb8daa0e50df4f66ffd6c0b)
@@ -55,5 +55,5 @@
 	asm volatile (
 		"pushq %[udata_des]\n"
-		"pushq %[stack_size]\n"
+		"pushq %[stack_top]\n"
 		"pushq %[ipl]\n"
 		"pushq %[utext_des]\n"
@@ -65,5 +65,6 @@
 		"iretq\n"
 		:: [udata_des] "i" (GDT_SELECTOR(UDATA_DES) | PL_USER),
-		   [stack_size] "r" (kernel_uarg->uspace_stack + STACK_SIZE),
+		   [stack_top] "r" ((uint8_t *) kernel_uarg->uspace_stack +
+		       kernel_uarg->uspace_stack_size),
 		   [ipl] "r" (ipl),
 		   [utext_des] "i" (GDT_SELECTOR(UTEXT_DES) | PL_USER),
@@ -74,6 +75,5 @@
 	
 	/* Unreachable */
-	while (1)
-		;
+	while (1);
 }
 
Index: kernel/arch/arm32/include/mm/page.h
===================================================================
--- kernel/arch/arm32/include/mm/page.h	(revision 0747468d84f2b1c59f16a0b00b33c12aa2a95e3f)
+++ kernel/arch/arm32/include/mm/page.h	(revision 97c76825acca82d15cb8daa0e50df4f66ffd6c0b)
@@ -40,4 +40,5 @@
 #include <mm/mm.h>
 #include <arch/exception.h>
+#include <arch/barrier.h>
 #include <trace.h>
 
@@ -118,5 +119,13 @@
 #define SET_PTL3_FLAGS_ARCH(ptl2, i, x)
 #define SET_FRAME_FLAGS_ARCH(ptl3, i, x) \
-        set_pt_level1_flags((pte_t *) (ptl3), (size_t) (i), (x))
+	set_pt_level1_flags((pte_t *) (ptl3), (size_t) (i), (x))
+
+/* Set PTE present bit accessors for each level. */
+#define SET_PTL1_PRESENT_ARCH(ptl0, i) \
+	set_pt_level0_present((pte_t *) (ptl0), (size_t) (i))
+#define SET_PTL2_PRESENT_ARCH(ptl1, i)
+#define SET_PTL3_PRESENT_ARCH(ptl2, i)
+#define SET_FRAME_PRESENT_ARCH(ptl3, i) \
+	set_pt_level1_present((pte_t *) (ptl3), (size_t) (i))
 
 #if defined(PROCESSOR_armv7_a)
@@ -126,4 +135,24 @@
 #endif
 
+#ifndef __ASM__
+NO_TRACE static inline void set_pt_level0_present(pte_t *pt, size_t i)
+{
+	pte_level0_t *p = &pt[i].l0;
+
+	p->should_be_zero = 0;
+	write_barrier();
+	p->descriptor_type = PTE_DESCRIPTOR_COARSE_TABLE;
+}
+
+
+NO_TRACE static inline void set_pt_level1_present(pte_t *pt, size_t i)
+{
+	pte_level1_t *p = &pt[i].l1;
+
+	p->descriptor_type = PTE_DESCRIPTOR_SMALL_PAGE;
+}
+
+#endif /* __ASM__ */
+
 #endif
 
Index: kernel/arch/arm32/include/mm/page_armv4.h
===================================================================
--- kernel/arch/arm32/include/mm/page_armv4.h	(revision 0747468d84f2b1c59f16a0b00b33c12aa2a95e3f)
+++ kernel/arch/arm32/include/mm/page_armv4.h	(revision 97c76825acca82d15cb8daa0e50df4f66ffd6c0b)
@@ -215,11 +215,8 @@
 	pte_level1_t *p = &pt[i].l1;
 	
-	if (flags & PAGE_NOT_PRESENT) {
+	if (flags & PAGE_NOT_PRESENT)
 		p->descriptor_type = PTE_DESCRIPTOR_NOT_PRESENT;
-		p->access_permission_3 = 1;
-	} else {
+	else
 		p->descriptor_type = PTE_DESCRIPTOR_SMALL_PAGE;
-		p->access_permission_3 = p->access_permission_0;
-	}
 	
 	p->cacheable = p->bufferable = (flags & PAGE_CACHEABLE) != 0;
Index: kernel/arch/arm32/src/userspace.c
===================================================================
--- kernel/arch/arm32/src/userspace.c	(revision 0747468d84f2b1c59f16a0b00b33c12aa2a95e3f)
+++ kernel/arch/arm32/src/userspace.c	(revision 97c76825acca82d15cb8daa0e50df4f66ffd6c0b)
@@ -92,5 +92,6 @@
 
 	/* set user stack */
-	ustate.sp = ((uint32_t)kernel_uarg->uspace_stack) + STACK_SIZE;
+	ustate.sp = ((uint32_t) kernel_uarg->uspace_stack) +
+	    kernel_uarg->uspace_stack_size;
 
 	/* set where uspace execution starts */
Index: kernel/arch/ia32/Makefile.inc
===================================================================
--- kernel/arch/ia32/Makefile.inc	(revision 0747468d84f2b1c59f16a0b00b33c12aa2a95e3f)
+++ kernel/arch/ia32/Makefile.inc	(revision 97c76825acca82d15cb8daa0e50df4f66ffd6c0b)
@@ -38,5 +38,4 @@
 GCC_CFLAGS += $(CMN1)
 ICC_CFLAGS += $(CMN1)
-SUNCC_CFLAGS += $(CMN1)
 CLANG_CFLAGS += $(CMN1)
 
@@ -50,25 +49,20 @@
 ifeq ($(PROCESSOR),athlon_xp)
 	CMN2 = -march=athlon-xp
-	SUNCC_CFLAGS += -xarch=ssea
 endif
 
 ifeq ($(PROCESSOR),athlon_mp)
 	CMN2 = -march=athlon-mp
-	SUNCC_CFLAGS += xarch=ssea
 endif
 
 ifeq ($(PROCESSOR),pentium3)
 	CMN2 = -march=pentium3
-	SUNCC_CFLAGS += -xarch=sse
 endif
 
 ifeq ($(PROCESSOR),pentium4)
 	CMN2 = -march=pentium4
-	SUNCC_CFLAGS += -xarch=sse2
 endif
 
 ifeq ($(PROCESSOR),core)
 	CMN2 = -march=prescott
-	SUNCC_CFLAGS += -xarch=sse3
 endif
 
Index: kernel/arch/ia32/include/mm/page.h
===================================================================
--- kernel/arch/ia32/include/mm/page.h	(revision 0747468d84f2b1c59f16a0b00b33c12aa2a95e3f)
+++ kernel/arch/ia32/include/mm/page.h	(revision 97c76825acca82d15cb8daa0e50df4f66ffd6c0b)
@@ -115,4 +115,12 @@
 	set_pt_flags((pte_t *) (ptl3), (size_t) (i), (x))
 
+/* Set PTE present bit accessors for each level. */
+#define SET_PTL1_PRESENT_ARCH(ptl0, i) \
+	set_pt_present((pte_t *) (ptl0), (size_t) (i))
+#define SET_PTL2_PRESENT_ARCH(ptl1, i)
+#define SET_PTL3_PRESENT_ARCH(ptl2, i)
+#define SET_FRAME_PRESENT_ARCH(ptl3, i) \
+	set_pt_present((pte_t *) (ptl3), (size_t) (i))
+
 /* Macros for querying the last level entries. */
 #define PTE_VALID_ARCH(p) \
@@ -194,4 +202,11 @@
 }
 
+NO_TRACE static inline void set_pt_present(pte_t *pt, size_t i)
+{
+	pte_t *p = &pt[i];
+
+	p->present = 1;
+}
+
 extern void page_arch_init(void);
 extern void page_fault(unsigned int, istate_t *);
Index: kernel/arch/ia32/src/mm/page.c
===================================================================
--- kernel/arch/ia32/src/mm/page.c	(revision 0747468d84f2b1c59f16a0b00b33c12aa2a95e3f)
+++ kernel/arch/ia32/src/mm/page.c	(revision 97c76825acca82d15cb8daa0e50df4f66ffd6c0b)
@@ -71,8 +71,5 @@
 	for (cur = 0; cur < min(config.identity_size, config.physmem_end);
 	    cur += FRAME_SIZE) {
-		flags = PAGE_CACHEABLE | PAGE_WRITE;
-		if ((PA2KA(cur) >= config.base) &&
-		    (PA2KA(cur) < config.base + config.kernel_size))
-			flags |= PAGE_GLOBAL;
+		flags = PAGE_GLOBAL | PAGE_CACHEABLE | PAGE_WRITE | PAGE_READ;
 		page_mapping_insert(AS_KERNEL, PA2KA(cur), cur, flags);
 	}
Index: kernel/arch/ia32/src/smp/apic.c
===================================================================
--- kernel/arch/ia32/src/smp/apic.c	(revision 0747468d84f2b1c59f16a0b00b33c12aa2a95e3f)
+++ kernel/arch/ia32/src/smp/apic.c	(revision 97c76825acca82d15cb8daa0e50df4f66ffd6c0b)
@@ -259,4 +259,24 @@
 }
 
+#define DELIVS_PENDING_SILENT_RETRIES	4	
+
+static void l_apic_wait_for_delivery(void)
+{
+	icr_t icr;
+	unsigned retries = 0;
+
+	do {
+		if (retries++ > DELIVS_PENDING_SILENT_RETRIES) {
+			retries = 0;
+#ifdef CONFIG_DEBUG
+			printf("IPI is pending.\n");
+#endif
+			delay(20);
+		}
+		icr.lo = l_apic[ICRlo];
+	} while (icr.delivs == DELIVS_PENDING);
+	
+}
+
 /** Send all CPUs excluding CPU IPI vector.
  *
@@ -279,11 +299,6 @@
 	
 	l_apic[ICRlo] = icr.lo;
-	
-	icr.lo = l_apic[ICRlo];
-	if (icr.delivs == DELIVS_PENDING) {
-#ifdef CONFIG_DEBUG
-		printf("IPI is pending.\n");
-#endif
-	}
+
+	l_apic_wait_for_delivery();
 	
 	return apic_poll_errors();
@@ -327,11 +342,7 @@
 		return 0;
 	
+	l_apic_wait_for_delivery();
+
 	icr.lo = l_apic[ICRlo];
-	if (icr.delivs == DELIVS_PENDING) {
-#ifdef CONFIG_DEBUG
-		printf("IPI is pending.\n");
-#endif
-	}
-	
 	icr.delmod = DELMOD_INIT;
 	icr.destmod = DESTMOD_PHYS;
Index: kernel/arch/ia32/src/userspace.c
===================================================================
--- kernel/arch/ia32/src/userspace.c	(revision 0747468d84f2b1c59f16a0b00b33c12aa2a95e3f)
+++ kernel/arch/ia32/src/userspace.c	(revision 97c76825acca82d15cb8daa0e50df4f66ffd6c0b)
@@ -63,5 +63,5 @@
 		
 		"pushl %[udata_des]\n"
-		"pushl %[stack_size]\n"
+		"pushl %[stack_top]\n"
 		"pushl %[ipl]\n"
 		"pushl %[utext_des]\n"
@@ -75,5 +75,6 @@
 		:
 		: [udata_des] "i" (GDT_SELECTOR(UDATA_DES) | PL_USER),
-		  [stack_size] "r" ((uint8_t *) kernel_uarg->uspace_stack + STACK_SIZE),
+		  [stack_top] "r" ((uint8_t *) kernel_uarg->uspace_stack +
+		      kernel_uarg->uspace_stack_size),
 		  [ipl] "r" (ipl),
 		  [utext_des] "i" (GDT_SELECTOR(UTEXT_DES) | PL_USER),
Index: kernel/arch/ia64/src/drivers/ski.c
===================================================================
--- kernel/arch/ia64/src/drivers/ski.c	(revision 0747468d84f2b1c59f16a0b00b33c12aa2a95e3f)
+++ kernel/arch/ia64/src/drivers/ski.c	(revision 97c76825acca82d15cb8daa0e50df4f66ffd6c0b)
@@ -150,6 +150,6 @@
 	
 	if (instance) {
-		instance->thread = thread_create(kskipoll, instance, TASK, 0,
-		    "kskipoll", true);
+		instance->thread = thread_create(kskipoll, instance, TASK,
+		    THREAD_FLAG_UNCOUNTED, "kskipoll");
 		
 		if (!instance->thread) {
Index: kernel/arch/ia64/src/ia64.c
===================================================================
--- kernel/arch/ia64/src/ia64.c	(revision 0747468d84f2b1c59f16a0b00b33c12aa2a95e3f)
+++ kernel/arch/ia64/src/ia64.c	(revision 97c76825acca82d15cb8daa0e50df4f66ffd6c0b)
@@ -232,14 +232,16 @@
 	 *
 	 * When calculating stack addresses, mind the stack split between the
-	 * memory stack and the RSE stack. Each occuppies STACK_SIZE / 2 bytes.
+	 * memory stack and the RSE stack. Each occuppies
+	 * uspace_stack_size / 2 bytes.
 	 */
 	switch_to_userspace((uintptr_t) kernel_uarg->uspace_entry,
-	    ((uintptr_t) kernel_uarg->uspace_stack) + STACK_SIZE / 2 -
+	    ((uintptr_t) kernel_uarg->uspace_stack) +
+	    kernel_uarg->uspace_stack_size / 2 -
 	    ALIGN_UP(STACK_ITEM_SIZE, STACK_ALIGNMENT),
-	    ((uintptr_t) kernel_uarg->uspace_stack) + STACK_SIZE / 2,
+	    ((uintptr_t) kernel_uarg->uspace_stack) +
+	    kernel_uarg->uspace_stack_size / 2,
 	    (uintptr_t) kernel_uarg->uspace_uarg, psr.value, rsc.value);
-
-	while (1)
-		;
+	
+	while (1);
 }
 
Index: kernel/arch/mips32/include/mm/page.h
===================================================================
--- kernel/arch/mips32/include/mm/page.h	(revision 0747468d84f2b1c59f16a0b00b33c12aa2a95e3f)
+++ kernel/arch/mips32/include/mm/page.h	(revision 97c76825acca82d15cb8daa0e50df4f66ffd6c0b)
@@ -128,4 +128,12 @@
 	set_pt_flags((pte_t *) (ptl3), (size_t) (i), (x))
 
+/* Set PTE present bit accessors for each level. */
+#define SET_PTL1_PRESENT_ARCH(ptl0, i) \
+	set_pt_present((pte_t *) (ptl0), (size_t) (i))
+#define SET_PTL2_PRESENT_ARCH(ptl1, i)
+#define SET_PTL3_PRESENT_ARCH(ptl2, i)
+#define SET_FRAME_PRESENT_ARCH(ptl3, i) \
+	set_pt_present((pte_t *) (ptl3), (size_t) (i))
+
 /* Last-level info macros. */
 #define PTE_VALID_ARCH(pte)			(*((uint32_t *) (pte)) != 0)
@@ -182,4 +190,12 @@
 }
 
+NO_TRACE static inline void set_pt_present(pte_t *pt, size_t i)
+{
+	pte_t *p = &pt[i];
+
+	p->p = 1;
+}
+	
+
 extern void page_arch_init(void);
 
Index: kernel/arch/mips32/src/mips32.c
===================================================================
--- kernel/arch/mips32/src/mips32.c	(revision 0747468d84f2b1c59f16a0b00b33c12aa2a95e3f)
+++ kernel/arch/mips32/src/mips32.c	(revision 97c76825acca82d15cb8daa0e50df4f66ffd6c0b)
@@ -211,5 +211,6 @@
 	    cp0_status_um_bit | cp0_status_ie_enabled_bit));
 	cp0_epc_write((uintptr_t) kernel_uarg->uspace_entry);
-	userspace_asm(((uintptr_t) kernel_uarg->uspace_stack + STACK_SIZE),
+	userspace_asm(((uintptr_t) kernel_uarg->uspace_stack +
+	    kernel_uarg->uspace_stack_size),
 	    (uintptr_t) kernel_uarg->uspace_uarg,
 	    (uintptr_t) kernel_uarg->uspace_entry);
Index: kernel/arch/mips64/src/mips64.c
===================================================================
--- kernel/arch/mips64/src/mips64.c	(revision 0747468d84f2b1c59f16a0b00b33c12aa2a95e3f)
+++ kernel/arch/mips64/src/mips64.c	(revision 97c76825acca82d15cb8daa0e50df4f66ffd6c0b)
@@ -188,5 +188,6 @@
 	    cp0_status_um_bit | cp0_status_ie_enabled_bit));
 	cp0_epc_write((uintptr_t) kernel_uarg->uspace_entry);
-	userspace_asm(((uintptr_t) kernel_uarg->uspace_stack + STACK_SIZE),
+	userspace_asm(((uintptr_t) kernel_uarg->uspace_stack +
+	    kernel_uarg->uspace_stack_size),
 	    (uintptr_t) kernel_uarg->uspace_uarg,
 	    (uintptr_t) kernel_uarg->uspace_entry);
Index: kernel/arch/ppc32/include/mm/page.h
===================================================================
--- kernel/arch/ppc32/include/mm/page.h	(revision 0747468d84f2b1c59f16a0b00b33c12aa2a95e3f)
+++ kernel/arch/ppc32/include/mm/page.h	(revision 97c76825acca82d15cb8daa0e50df4f66ffd6c0b)
@@ -128,4 +128,14 @@
 #define SET_FRAME_FLAGS_ARCH(ptl3, i, x) \
 	set_pt_flags((pte_t *) (ptl3), (size_t) (i), (x))
+
+/* Set PTE present accessors for each level. */
+#define SET_PTL1_PRESENT_ARCH(ptl0, i) \
+	set_pt_present((pte_t *) (ptl0), (size_t) (i))
+
+#define SET_PTL2_PRESENT_ARCH(ptl1, i)
+#define SET_PTL3_PRESENT_ARCH(ptl2, i)
+
+#define SET_FRAME_PRESENT_ARCH(ptl3, i) \
+	set_pt_present((pte_t *) (ptl3), (size_t) (i))
 
 /* Macros for querying the last-level PTEs. */
@@ -175,4 +185,11 @@
 }
 
+NO_TRACE static inline void set_pt_present(pte_t *pt, size_t i)
+{
+	pte_t *entry = &pt[i];
+
+	entry->present = 1;
+}
+
 extern void page_arch_init(void);
 
Index: kernel/arch/ppc32/src/ppc32.c
===================================================================
--- kernel/arch/ppc32/src/ppc32.c	(revision 0747468d84f2b1c59f16a0b00b33c12aa2a95e3f)
+++ kernel/arch/ppc32/src/ppc32.c	(revision 97c76825acca82d15cb8daa0e50df4f66ffd6c0b)
@@ -269,5 +269,6 @@
 {
 	userspace_asm((uintptr_t) kernel_uarg->uspace_uarg,
-	    (uintptr_t) kernel_uarg->uspace_stack + STACK_SIZE - SP_DELTA,
+	    (uintptr_t) kernel_uarg->uspace_stack +
+	    kernel_uarg->uspace_stack_size - SP_DELTA,
 	    (uintptr_t) kernel_uarg->uspace_entry);
 	
Index: kernel/arch/sparc64/Makefile.inc
===================================================================
--- kernel/arch/sparc64/Makefile.inc	(revision 0747468d84f2b1c59f16a0b00b33c12aa2a95e3f)
+++ kernel/arch/sparc64/Makefile.inc	(revision 97c76825acca82d15cb8daa0e50df4f66ffd6c0b)
@@ -32,5 +32,4 @@
 
 GCC_CFLAGS += -m64 -mcpu=ultrasparc -mcmodel=medlow -mno-fpu
-SUNCC_CFLAGS += -m64 -xarch=sparc -xregs=appl,no%float
 
 LFLAGS += -no-check-sections
Index: kernel/arch/sparc64/src/drivers/niagara.c
===================================================================
--- kernel/arch/sparc64/src/drivers/niagara.c	(revision 0747468d84f2b1c59f16a0b00b33c12aa2a95e3f)
+++ kernel/arch/sparc64/src/drivers/niagara.c	(revision 97c76825acca82d15cb8daa0e50df4f66ffd6c0b)
@@ -184,6 +184,6 @@
 	
 	instance = malloc(sizeof(niagara_instance_t), FRAME_ATOMIC);
-	instance->thread = thread_create(kniagarapoll, NULL, TASK, 0,
-	    "kniagarapoll", true);
+	instance->thread = thread_create(kniagarapoll, NULL, TASK,
+	    THREAD_FLAG_UNCOUNTED, "kniagarapoll");
 	
 	if (!instance->thread) {
Index: kernel/arch/sparc64/src/proc/sun4u/scheduler.c
===================================================================
--- kernel/arch/sparc64/src/proc/sun4u/scheduler.c	(revision 0747468d84f2b1c59f16a0b00b33c12aa2a95e3f)
+++ kernel/arch/sparc64/src/proc/sun4u/scheduler.c	(revision 97c76825acca82d15cb8daa0e50df4f66ffd6c0b)
@@ -51,5 +51,5 @@
 void before_thread_runs_arch(void)
 {
-	if ((THREAD->flags & THREAD_FLAG_USPACE)) {
+	if (THREAD->uspace) {
 		/*
 		 * Write kernel stack address to %g6 of the alternate and
@@ -74,6 +74,6 @@
 void after_thread_ran_arch(void)
 {
-	if ((THREAD->flags & THREAD_FLAG_USPACE)) {
-		/* sample the state of the userspace window buffer */	
+	if (THREAD->uspace) {
+		/* sample the state of the userspace window buffer */
 		THREAD->arch.uspace_window_buffer = (uint8_t *) read_from_ag_g7();
 	}
Index: kernel/arch/sparc64/src/proc/sun4v/scheduler.c
===================================================================
--- kernel/arch/sparc64/src/proc/sun4v/scheduler.c	(revision 0747468d84f2b1c59f16a0b00b33c12aa2a95e3f)
+++ kernel/arch/sparc64/src/proc/sun4v/scheduler.c	(revision 97c76825acca82d15cb8daa0e50df4f66ffd6c0b)
@@ -54,5 +54,5 @@
 void before_thread_runs_arch(void)
 {
-	if ((THREAD->flags & THREAD_FLAG_USPACE)) {
+	if (THREAD->uspace) {
 		uint64_t sp = (uintptr_t) THREAD->kstack + STACK_SIZE -
 		    (STACK_BIAS + ALIGN_UP(STACK_ITEM_SIZE, STACK_ALIGNMENT));
@@ -66,6 +66,6 @@
 void after_thread_ran_arch(void)
 {
-	if ((THREAD->flags & THREAD_FLAG_USPACE)) {
-		/* sample the state of the userspace window buffer */	
+	if (THREAD->uspace) {
+		/* sample the state of the userspace window buffer */
 		THREAD->arch.uspace_window_buffer =
 		    (uint8_t *) asi_u64_read(ASI_SCRATCHPAD, SCRATCHPAD_WBUF);
Index: kernel/arch/sparc64/src/proc/thread.c
===================================================================
--- kernel/arch/sparc64/src/proc/thread.c	(revision 0747468d84f2b1c59f16a0b00b33c12aa2a95e3f)
+++ kernel/arch/sparc64/src/proc/thread.c	(revision 97c76825acca82d15cb8daa0e50df4f66ffd6c0b)
@@ -61,5 +61,5 @@
 void thread_create_arch(thread_t *t)
 {
-	if ((t->flags & THREAD_FLAG_USPACE) && (!t->arch.uspace_window_buffer))
+	if ((t->uspace) && (!t->arch.uspace_window_buffer))
 		{
 		/*
Index: kernel/arch/sparc64/src/smp/sun4u/ipi.c
===================================================================
--- kernel/arch/sparc64/src/smp/sun4u/ipi.c	(revision 0747468d84f2b1c59f16a0b00b33c12aa2a95e3f)
+++ kernel/arch/sparc64/src/smp/sun4u/ipi.c	(revision 97c76825acca82d15cb8daa0e50df4f66ffd6c0b)
@@ -124,5 +124,5 @@
 			(void) interrupts_disable();
 		}
-	} while (done);
+	} while (!done);
 	
 	preemption_enable();
Index: kernel/arch/sparc64/src/sun4u/sparc64.c
===================================================================
--- kernel/arch/sparc64/src/sun4u/sparc64.c	(revision 0747468d84f2b1c59f16a0b00b33c12aa2a95e3f)
+++ kernel/arch/sparc64/src/sun4u/sparc64.c	(revision 97c76825acca82d15cb8daa0e50df4f66ffd6c0b)
@@ -156,11 +156,11 @@
 	(void) interrupts_disable();
 	switch_to_userspace((uintptr_t) kernel_uarg->uspace_entry,
-	    ((uintptr_t) kernel_uarg->uspace_stack) + STACK_SIZE
-	    - (ALIGN_UP(STACK_ITEM_SIZE, STACK_ALIGNMENT) + STACK_BIAS),
+	    ((uintptr_t) kernel_uarg->uspace_stack) +
+	    kernel_uarg->uspace_stack_size -
+	    (ALIGN_UP(STACK_ITEM_SIZE, STACK_ALIGNMENT) + STACK_BIAS),
 	    (uintptr_t) kernel_uarg->uspace_uarg);
-
-	for (;;)
-		;
-	/* not reached */
+	
+	/* Not reached */
+	while (1);
 }
 
Index: kernel/arch/sparc64/src/sun4v/sparc64.c
===================================================================
--- kernel/arch/sparc64/src/sun4v/sparc64.c	(revision 0747468d84f2b1c59f16a0b00b33c12aa2a95e3f)
+++ kernel/arch/sparc64/src/sun4v/sparc64.c	(revision 97c76825acca82d15cb8daa0e50df4f66ffd6c0b)
@@ -154,11 +154,11 @@
 	(void) interrupts_disable();
 	switch_to_userspace((uintptr_t) kernel_uarg->uspace_entry,
-	    ((uintptr_t) kernel_uarg->uspace_stack) + STACK_SIZE
-	    - (ALIGN_UP(STACK_ITEM_SIZE, STACK_ALIGNMENT) + STACK_BIAS),
+	    ((uintptr_t) kernel_uarg->uspace_stack) +
+	    kernel_uarg->uspace_stack_size -
+	    (ALIGN_UP(STACK_ITEM_SIZE, STACK_ALIGNMENT) + STACK_BIAS),
 	    (uintptr_t) kernel_uarg->uspace_uarg);
-
-	for (;;)
-		;
-	/* not reached */
+	
+	/* Not reached */
+	while (1);
 }
 
Index: kernel/genarch/include/mm/page_pt.h
===================================================================
--- kernel/genarch/include/mm/page_pt.h	(revision 0747468d84f2b1c59f16a0b00b33c12aa2a95e3f)
+++ kernel/genarch/include/mm/page_pt.h	(revision 97c76825acca82d15cb8daa0e50df4f66ffd6c0b)
@@ -115,4 +115,13 @@
 
 /*
+ * These macros are provided to set the present bit within the page tables.
+ *
+ */
+#define SET_PTL1_PRESENT(ptl0, i)   SET_PTL1_PRESENT_ARCH(ptl0, i)
+#define SET_PTL2_PRESENT(ptl1, i)   SET_PTL2_PRESENT_ARCH(ptl1, i)
+#define SET_PTL3_PRESENT(ptl2, i)   SET_PTL3_PRESENT_ARCH(ptl2, i)
+#define SET_FRAME_PRESENT(ptl3, i)  SET_FRAME_PRESENT_ARCH(ptl3, i)
+
+/*
  * Macros for querying the last-level PTEs.
  *
Index: kernel/genarch/src/fb/fb.c
===================================================================
--- kernel/genarch/src/fb/fb.c	(revision 0747468d84f2b1c59f16a0b00b33c12aa2a95e3f)
+++ kernel/genarch/src/fb/fb.c	(revision 97c76825acca82d15cb8daa0e50df4f66ffd6c0b)
@@ -390,6 +390,6 @@
 			    instance->position / instance->cols, false);
 			instance->position++;
-		} while ((instance->position % 8)
-		    && (instance->position < instance->cols * instance->rows));
+		} while (((instance->position % instance->cols) % 8 != 0) &&
+		    (instance->position < instance->cols * instance->rows));
 		break;
 	default:
Index: kernel/genarch/src/kbrd/kbrd.c
===================================================================
--- kernel/genarch/src/kbrd/kbrd.c	(revision 0747468d84f2b1c59f16a0b00b33c12aa2a95e3f)
+++ kernel/genarch/src/kbrd/kbrd.c	(revision 97c76825acca82d15cb8daa0e50df4f66ffd6c0b)
@@ -158,6 +158,6 @@
 	    = malloc(sizeof(kbrd_instance_t), FRAME_ATOMIC);
 	if (instance) {
-		instance->thread
-			= thread_create(kkbrd, (void *) instance, TASK, 0, "kkbrd", false);
+		instance->thread = thread_create(kkbrd, (void *) instance,
+		    TASK, THREAD_FLAG_NONE, "kkbrd");
 		
 		if (!instance->thread) {
Index: kernel/genarch/src/mm/as_ht.c
===================================================================
--- kernel/genarch/src/mm/as_ht.c	(revision 0747468d84f2b1c59f16a0b00b33c12aa2a95e3f)
+++ kernel/genarch/src/mm/as_ht.c	(revision 97c76825acca82d15cb8daa0e50df4f66ffd6c0b)
@@ -78,6 +78,6 @@
 		hash_table_create(&page_ht, PAGE_HT_ENTRIES, 2, &ht_operations);
 		mutex_initialize(&page_ht_lock, MUTEX_PASSIVE);
-		pte_cache = slab_cache_create("pte_cache", sizeof(pte_t), 0, NULL, NULL,
-		    SLAB_CACHE_MAGDEFERRED);
+		pte_cache = slab_cache_create("pte_t", sizeof(pte_t), 0,
+		    NULL, NULL, SLAB_CACHE_MAGDEFERRED);
 	}
 	
Index: kernel/genarch/src/mm/page_ht.c
===================================================================
--- kernel/genarch/src/mm/page_ht.c	(revision 0747468d84f2b1c59f16a0b00b33c12aa2a95e3f)
+++ kernel/genarch/src/mm/page_ht.c	(revision 97c76825acca82d15cb8daa0e50df4f66ffd6c0b)
@@ -45,4 +45,5 @@
 #include <typedefs.h>
 #include <arch/asm.h>
+#include <arch/barrier.h>
 #include <synch/spinlock.h>
 #include <arch.h>
@@ -207,4 +208,6 @@
 		pte->page = ALIGN_DOWN(page, PAGE_SIZE);
 		pte->frame = ALIGN_DOWN(frame, FRAME_SIZE);
+
+		write_barrier();
 		
 		hash_table_insert(&page_ht, key, &pte->link);
Index: kernel/genarch/src/mm/page_pt.c
===================================================================
--- kernel/genarch/src/mm/page_pt.c	(revision 0747468d84f2b1c59f16a0b00b33c12aa2a95e3f)
+++ kernel/genarch/src/mm/page_pt.c	(revision 97c76825acca82d15cb8daa0e50df4f66ffd6c0b)
@@ -43,4 +43,5 @@
 #include <arch/mm/page.h>
 #include <arch/mm/as.h>
+#include <arch/barrier.h>
 #include <typedefs.h>
 #include <arch/asm.h>
@@ -48,4 +49,5 @@
 #include <align.h>
 #include <macros.h>
+#include <bitops.h>
 
 static void pt_mapping_insert(as_t *, uintptr_t, uintptr_t, unsigned int);
@@ -85,6 +87,8 @@
 		SET_PTL1_ADDRESS(ptl0, PTL0_INDEX(page), KA2PA(newpt));
 		SET_PTL1_FLAGS(ptl0, PTL0_INDEX(page),
-		    PAGE_PRESENT | PAGE_USER | PAGE_EXEC | PAGE_CACHEABLE |
+		    PAGE_NOT_PRESENT | PAGE_USER | PAGE_EXEC | PAGE_CACHEABLE |
 		    PAGE_WRITE);
+		write_barrier();
+		SET_PTL1_PRESENT(ptl0, PTL0_INDEX(page));
 	}
 	
@@ -97,6 +101,8 @@
 		SET_PTL2_ADDRESS(ptl1, PTL1_INDEX(page), KA2PA(newpt));
 		SET_PTL2_FLAGS(ptl1, PTL1_INDEX(page),
-		    PAGE_PRESENT | PAGE_USER | PAGE_EXEC | PAGE_CACHEABLE |
+		    PAGE_NOT_PRESENT | PAGE_USER | PAGE_EXEC | PAGE_CACHEABLE |
 		    PAGE_WRITE);
+		write_barrier();
+		SET_PTL2_PRESENT(ptl1, PTL1_INDEX(page));	
 	}
 	
@@ -109,6 +115,8 @@
 		SET_PTL3_ADDRESS(ptl2, PTL2_INDEX(page), KA2PA(newpt));
 		SET_PTL3_FLAGS(ptl2, PTL2_INDEX(page),
-		    PAGE_PRESENT | PAGE_USER | PAGE_EXEC | PAGE_CACHEABLE |
+		    PAGE_NOT_PRESENT | PAGE_USER | PAGE_EXEC | PAGE_CACHEABLE |
 		    PAGE_WRITE);
+		write_barrier();
+		SET_PTL3_PRESENT(ptl2, PTL2_INDEX(page));
 	}
 	
@@ -116,5 +124,7 @@
 	
 	SET_FRAME_ADDRESS(ptl3, PTL3_INDEX(page), frame);
-	SET_FRAME_FLAGS(ptl3, PTL3_INDEX(page), flags);
+	SET_FRAME_FLAGS(ptl3, PTL3_INDEX(page), flags | PAGE_NOT_PRESENT);
+	write_barrier();
+	SET_FRAME_PRESENT(ptl3, PTL3_INDEX(page));
 }
 
@@ -278,16 +288,40 @@
 	if (GET_PTL1_FLAGS(ptl0, PTL0_INDEX(page)) & PAGE_NOT_PRESENT)
 		return NULL;
+
+	read_barrier();
 	
 	pte_t *ptl1 = (pte_t *) PA2KA(GET_PTL1_ADDRESS(ptl0, PTL0_INDEX(page)));
 	if (GET_PTL2_FLAGS(ptl1, PTL1_INDEX(page)) & PAGE_NOT_PRESENT)
 		return NULL;
+
+#if (PTL1_ENTRIES != 0)
+	read_barrier();
+#endif
 	
 	pte_t *ptl2 = (pte_t *) PA2KA(GET_PTL2_ADDRESS(ptl1, PTL1_INDEX(page)));
 	if (GET_PTL3_FLAGS(ptl2, PTL2_INDEX(page)) & PAGE_NOT_PRESENT)
 		return NULL;
+
+#if (PTL2_ENTRIES != 0)
+	read_barrier();
+#endif
 	
 	pte_t *ptl3 = (pte_t *) PA2KA(GET_PTL3_ADDRESS(ptl2, PTL2_INDEX(page)));
 	
 	return &ptl3[PTL3_INDEX(page)];
+}
+
+/** Return the size of the region mapped by a single PTL0 entry.
+ *
+ * @return Size of the region mapped by a single PTL0 entry.
+ */
+static uintptr_t ptl0_step_get(void)
+{
+	size_t va_bits;
+
+	va_bits = fnzb(PTL0_ENTRIES) + fnzb(PTL1_ENTRIES) + fnzb(PTL2_ENTRIES) +
+	    fnzb(PTL3_ENTRIES) + PAGE_WIDTH;
+
+	return 1UL << (va_bits - fnzb(PTL0_ENTRIES));
 }
 
@@ -309,5 +343,5 @@
 {
 	uintptr_t ptl0 = PA2KA((uintptr_t) AS_KERNEL->genarch.page_table);
-	uintptr_t ptl0step = (((uintptr_t) -1) / PTL0_ENTRIES) + 1;
+	uintptr_t ptl0_step = ptl0_step_get();
 	size_t order;
 	uintptr_t addr;
@@ -321,9 +355,8 @@
 #endif
 
-	ASSERT(ispwr2(ptl0step));
 	ASSERT(size > 0);
 
-	for (addr = ALIGN_DOWN(base, ptl0step); addr - 1 < base + size - 1;
-	    addr += ptl0step) {
+	for (addr = ALIGN_DOWN(base, ptl0_step); addr - 1 < base + size - 1;
+	    addr += ptl0_step) {
 		uintptr_t l1;
 
@@ -332,6 +365,6 @@
 		SET_PTL1_ADDRESS(ptl0, PTL0_INDEX(addr), KA2PA(l1));
 		SET_PTL1_FLAGS(ptl0, PTL0_INDEX(addr),
-		    PAGE_PRESENT | PAGE_USER | PAGE_EXEC | PAGE_CACHEABLE |
-		    PAGE_WRITE);
+		    PAGE_PRESENT | PAGE_USER | PAGE_CACHEABLE |
+		    PAGE_EXEC | PAGE_WRITE | PAGE_READ);
 	}
 }
Index: kernel/genarch/src/srln/srln.c
===================================================================
--- kernel/genarch/src/srln/srln.c	(revision 0747468d84f2b1c59f16a0b00b33c12aa2a95e3f)
+++ kernel/genarch/src/srln/srln.c	(revision 97c76825acca82d15cb8daa0e50df4f66ffd6c0b)
@@ -130,6 +130,6 @@
 	    = malloc(sizeof(srln_instance_t), FRAME_ATOMIC);
 	if (instance) {
-		instance->thread
-			= thread_create(ksrln, (void *) instance, TASK, 0, "ksrln", false);
+		instance->thread = thread_create(ksrln, (void *) instance,
+		    TASK, THREAD_FLAG_NONE, "ksrln");
 		
 		if (!instance->thread) {
Index: kernel/generic/include/console/prompt.h
===================================================================
--- kernel/generic/include/console/prompt.h	(revision 97c76825acca82d15cb8daa0e50df4f66ffd6c0b)
+++ kernel/generic/include/console/prompt.h	(revision 97c76825acca82d15cb8daa0e50df4f66ffd6c0b)
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2012 Vojtech Horky
+ * 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 genericconsole
+ * @{
+ */
+/** @file
+ */
+
+#ifndef KERN_CONSOLE_PROMPT_H_
+#define KERN_CONSOLE_PROMPT_H_
+
+#include <console/chardev.h>
+
+#define MAX_TAB_HINTS 37
+
+extern bool console_prompt_display_all_hints(indev_t *, size_t);
+extern bool console_prompt_more_hints(indev_t *, size_t *);
+
+#endif
+
+/** @}
+ */
Index: kernel/generic/include/debug.h
===================================================================
--- kernel/generic/include/debug.h	(revision 0747468d84f2b1c59f16a0b00b33c12aa2a95e3f)
+++ kernel/generic/include/debug.h	(revision 97c76825acca82d15cb8daa0e50df4f66ffd6c0b)
@@ -37,5 +37,5 @@
 
 #include <panic.h>
-#include <symtab.h>
+#include <symtab_lookup.h>
 
 #define CALLER  ((uintptr_t) __builtin_return_address(0))
Index: kernel/generic/include/ipc/ipc.h
===================================================================
--- kernel/generic/include/ipc/ipc.h	(revision 0747468d84f2b1c59f16a0b00b33c12aa2a95e3f)
+++ kernel/generic/include/ipc/ipc.h	(revision 97c76825acca82d15cb8daa0e50df4f66ffd6c0b)
@@ -148,5 +148,5 @@
 extern int ipc_call(phone_t *, call_t *);
 extern int ipc_call_sync(phone_t *, call_t *);
-extern call_t * ipc_wait_for_call(answerbox_t *, uint32_t, unsigned int);
+extern call_t *ipc_wait_for_call(answerbox_t *, uint32_t, unsigned int);
 extern int ipc_forward(call_t *, phone_t *, answerbox_t *, unsigned int);
 extern void ipc_answer(answerbox_t *, call_t *);
Index: kernel/generic/include/ipc/ipcrsc.h
===================================================================
--- kernel/generic/include/ipc/ipcrsc.h	(revision 0747468d84f2b1c59f16a0b00b33c12aa2a95e3f)
+++ kernel/generic/include/ipc/ipcrsc.h	(revision 97c76825acca82d15cb8daa0e50df4f66ffd6c0b)
@@ -39,8 +39,8 @@
 #include <ipc/ipc.h>
 
-extern call_t * get_call(sysarg_t callid);
-extern int phone_alloc(task_t *t);
-extern void phone_connect(int phoneid, answerbox_t *box);
-extern void phone_dealloc(int phoneid);
+extern call_t *get_call(sysarg_t);
+extern int phone_alloc(task_t *);
+extern void phone_connect(int, answerbox_t *);
+extern void phone_dealloc(int);
 
 #endif
Index: kernel/generic/include/lib/ra.h
===================================================================
--- kernel/generic/include/lib/ra.h	(revision 0747468d84f2b1c59f16a0b00b33c12aa2a95e3f)
+++ kernel/generic/include/lib/ra.h	(revision 97c76825acca82d15cb8daa0e50df4f66ffd6c0b)
@@ -42,5 +42,5 @@
 
 typedef struct {
-	SPINLOCK_DECLARE(lock);
+	IRQ_SPINLOCK_DECLARE(lock);
 	list_t spans;		/**< List of arena's spans. */
 } ra_arena_t;
Index: kernel/generic/include/mm/slab.h
===================================================================
--- kernel/generic/include/mm/slab.h	(revision 0747468d84f2b1c59f16a0b00b33c12aa2a95e3f)
+++ kernel/generic/include/mm/slab.h	(revision 97c76825acca82d15cb8daa0e50df4f66ffd6c0b)
@@ -81,5 +81,5 @@
 	slab_magazine_t *current;
 	slab_magazine_t *last;
-	SPINLOCK_DECLARE(lock);
+	IRQ_SPINLOCK_DECLARE(lock);
 } slab_mag_cache_t;
 
@@ -113,8 +113,8 @@
 	list_t full_slabs;     /**< List of full slabs */
 	list_t partial_slabs;  /**< List of partial slabs */
-	SPINLOCK_DECLARE(slablock);
+	IRQ_SPINLOCK_DECLARE(slablock);
 	/* Magazines */
 	list_t magazines;  /**< List o full magazines */
-	SPINLOCK_DECLARE(maglock);
+	IRQ_SPINLOCK_DECLARE(maglock);
 	
 	/** CPU cache */
Index: kernel/generic/include/proc/program.h
===================================================================
--- kernel/generic/include/proc/program.h	(revision 0747468d84f2b1c59f16a0b00b33c12aa2a95e3f)
+++ kernel/generic/include/proc/program.h	(revision 97c76825acca82d15cb8daa0e50df4f66ffd6c0b)
@@ -50,4 +50,5 @@
 	struct task *task;           /**< Program task */
 	struct thread *main_thread;  /**< Program main thread */
+	unsigned int loader_status;  /**< Binary loader error status */
 } program_t;
 
Index: kernel/generic/include/proc/thread.h
===================================================================
--- kernel/generic/include/proc/thread.h	(revision 0747468d84f2b1c59f16a0b00b33c12aa2a95e3f)
+++ kernel/generic/include/proc/thread.h	(revision 97c76825acca82d15cb8daa0e50df4f66ffd6c0b)
@@ -54,21 +54,13 @@
 
 /* Thread flags */
-
-/** Thread cannot be migrated to another CPU.
- *
- * When using this flag, the caller must set cpu in the thread_t
- * structure manually before calling thread_ready (even on uniprocessor).
- *
- */
-#define THREAD_FLAG_WIRED  (1 << 0)
-
-/** Thread was migrated to another CPU and has not run yet. */
-#define THREAD_FLAG_STOLEN  (1 << 1)
-
-/** Thread executes in userspace. */
-#define THREAD_FLAG_USPACE  (1 << 2)
-
-/** Thread will be attached by the caller. */
-#define THREAD_FLAG_NOATTACH  (1 << 3)
+typedef enum {
+	THREAD_FLAG_NONE = 0,
+	/** Thread executes in user space. */
+	THREAD_FLAG_USPACE = (1 << 0),
+	/** Thread will be attached by the caller. */
+	THREAD_FLAG_NOATTACH = (1 << 1),
+	/** Thread accounting doesn't affect accumulated task accounting. */
+	THREAD_FLAG_UNCOUNTED = (1 << 2)
+} thread_flags_t;
 
 /** Thread structure. There is one per thread. */
@@ -147,5 +139,5 @@
 	
 	fpu_context_t *saved_fpu_context;
-	int fpu_context_exists;
+	bool fpu_context_exists;
 	
 	/*
@@ -154,18 +146,22 @@
 	 * thread. This disables migration.
 	 */
-	int fpu_context_engaged;
+	bool fpu_context_engaged;
 	
 	/* The thread will not be migrated if nomigrate is non-zero. */
-	int nomigrate;
-	
-	/** Thread's state. */
+	unsigned int nomigrate;
+	
+	/** Thread state. */
 	state_t state;
-	/** Thread's flags. */
-	unsigned int flags;
-	
-	/** Thread's CPU. */
+	
+	/** Thread CPU. */
 	cpu_t *cpu;
 	/** Containing task. */
 	task_t *task;
+	/** Thread is wired to CPU. */
+	bool wired;
+	/** Thread was migrated to another CPU and has not run yet. */
+	bool stolen;
+	/** Thread is executed in user space. */
+	bool uspace;
 	
 	/** Ticks before preemption. */
@@ -216,5 +212,6 @@
 extern void thread_init(void);
 extern thread_t *thread_create(void (*)(void *), void *, task_t *,
-    unsigned int, const char *, bool);
+    thread_flags_t, const char *);
+extern void thread_wire(thread_t *, cpu_t *);
 extern void thread_attach(thread_t *, task_t *);
 extern void thread_ready(thread_t *);
Index: kernel/generic/include/symtab.h
===================================================================
--- kernel/generic/include/symtab.h	(revision 0747468d84f2b1c59f16a0b00b33c12aa2a95e3f)
+++ kernel/generic/include/symtab.h	(revision 97c76825acca82d15cb8daa0e50df4f66ffd6c0b)
@@ -36,27 +36,9 @@
 #define KERN_SYMTAB_H_
 
-#include <typedefs.h>
+#include <symtab_lookup.h>
+#include <console/chardev.h>
 
-#define MAX_SYMBOL_NAME  64
-
-struct symtab_entry {
-	uint64_t address_le;
-	char symbol_name[MAX_SYMBOL_NAME];
-};
-
-extern int symtab_name_lookup(uintptr_t, const char **, uintptr_t *);
-extern const char *symtab_fmt_name_lookup(uintptr_t);
-extern int symtab_addr_lookup(const char *, uintptr_t *);
 extern void symtab_print_search(const char *);
-extern int symtab_compl(char *, size_t);
-
-#ifdef CONFIG_SYMTAB
-
-/** Symtable linked together by build process
- *
- */
-extern struct symtab_entry symbol_table[];
-
-#endif /* CONFIG_SYMTAB */
+extern int symtab_compl(char *, size_t, indev_t *);
 
 #endif
Index: kernel/generic/include/symtab_lookup.h
===================================================================
--- kernel/generic/include/symtab_lookup.h	(revision 97c76825acca82d15cb8daa0e50df4f66ffd6c0b)
+++ kernel/generic/include/symtab_lookup.h	(revision 97c76825acca82d15cb8daa0e50df4f66ffd6c0b)
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2005 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 generic
+ * @{
+ */
+/** @file
+ */
+
+#ifndef KERN_SYMTAB_LOOKUP_H_
+#define KERN_SYMTAB_LOOKUP_H_
+
+#include <typedefs.h>
+
+#define MAX_SYMBOL_NAME  64
+
+struct symtab_entry {
+	uint64_t address_le;
+	char symbol_name[MAX_SYMBOL_NAME];
+};
+
+extern int symtab_name_lookup(uintptr_t, const char **, uintptr_t *);
+extern const char *symtab_fmt_name_lookup(uintptr_t);
+extern int symtab_addr_lookup(const char *, uintptr_t *);
+
+#ifdef CONFIG_SYMTAB
+
+/** Symtable linked together by build process
+ *
+ */
+extern struct symtab_entry symbol_table[];
+
+#endif /* CONFIG_SYMTAB */
+
+#endif
+
+/** @}
+ */
Index: kernel/generic/src/adt/btree.c
===================================================================
--- kernel/generic/src/adt/btree.c	(revision 0747468d84f2b1c59f16a0b00b33c12aa2a95e3f)
+++ kernel/generic/src/adt/btree.c	(revision 97c76825acca82d15cb8daa0e50df4f66ffd6c0b)
@@ -71,5 +71,5 @@
 void btree_init(void)
 {
-	btree_node_slab = slab_cache_create("btree_node_slab",
+	btree_node_slab = slab_cache_create("btree_node_t",
 	    sizeof(btree_node_t), 0, NULL, NULL, SLAB_CACHE_MAGDEFERRED);
 }
Index: kernel/generic/src/console/cmd.c
===================================================================
--- kernel/generic/src/console/cmd.c	(revision 0747468d84f2b1c59f16a0b00b33c12aa2a95e3f)
+++ kernel/generic/src/console/cmd.c	(revision 97c76825acca82d15cb8daa0e50df4f66ffd6c0b)
@@ -724,11 +724,7 @@
 		thread_t *thread;
 		if ((thread = thread_create((void (*)(void *)) cmd_call0,
-		    (void *) argv, TASK, THREAD_FLAG_WIRED, "call0", false))) {
-			irq_spinlock_lock(&thread->lock, true);
-			thread->cpu = &cpus[i];
-			irq_spinlock_unlock(&thread->lock, true);
-			
+		    (void *) argv, TASK, THREAD_FLAG_NONE, "call0"))) {
 			printf("cpu%u: ", i);
-			
+			thread_wire(thread, &cpus[i]);
 			thread_ready(thread);
 			thread_join(thread);
Index: kernel/generic/src/console/kconsole.c
===================================================================
--- kernel/generic/src/console/kconsole.c	(revision 0747468d84f2b1c59f16a0b00b33c12aa2a95e3f)
+++ kernel/generic/src/console/kconsole.c	(revision 97c76825acca82d15cb8daa0e50df4f66ffd6c0b)
@@ -43,4 +43,5 @@
 #include <console/chardev.h>
 #include <console/cmd.h>
+#include <console/prompt.h>
 #include <print.h>
 #include <panic.h>
@@ -201,12 +202,20 @@
  *
  */
-NO_TRACE static int cmdtab_compl(char *input, size_t size)
+NO_TRACE static int cmdtab_compl(char *input, size_t size, indev_t * indev)
 {
 	const char *name = input;
 	
 	size_t found = 0;
+	/* Maximum Match Length : Length of longest matching common substring in
+	   case more than one match is found */
+	size_t max_match_len = size;
+	size_t max_match_len_tmp = size;
+	size_t input_len = str_length(input);
 	link_t *pos = NULL;
 	const char *hint;
 	char *output = malloc(MAX_CMDLINE, 0);
+	size_t hints_to_show = MAX_TAB_HINTS - 1;
+	size_t total_hints_shown = 0;
+	bool continue_showing_hints = true;
 	
 	output[0] = 0;
@@ -218,4 +227,10 @@
 		pos = pos->next;
 		found++;
+	}
+	
+	/* If possible completions are more than MAX_TAB_HINTS, ask user whether to display them or not. */
+	if (found > MAX_TAB_HINTS) {
+		printf("\n");
+		continue_showing_hints = console_prompt_display_all_hints(indev, found);
 	}
 	
@@ -225,7 +240,22 @@
 		while (cmdtab_search_one(name, &pos)) {
 			cmd_info_t *hlp = list_get_instance(pos, cmd_info_t, link);
-			printf("%s (%s)\n", hlp->name, hlp->description);
+
+			if (continue_showing_hints) {
+				printf("%s (%s)\n", hlp->name, hlp->description);
+				--hints_to_show;
+				++total_hints_shown;
+
+				if (hints_to_show == 0 && total_hints_shown != found) { /* Time to ask user to continue */
+					continue_showing_hints = console_prompt_more_hints(indev, &hints_to_show);
+				}
+			}
+
 			pos = pos->next;
-		}
+			for(max_match_len_tmp = 0; output[max_match_len_tmp] == hlp->name[input_len + max_match_len_tmp]
+					&& max_match_len_tmp < max_match_len; ++max_match_len_tmp);
+			max_match_len = max_match_len_tmp;
+		}
+		/* keep only the characters common in all completions */
+		output[max_match_len] = 0;
 	}
 	
@@ -294,23 +324,15 @@
 			if (beg == 0) {
 				/* Command completion */
-				found = cmdtab_compl(tmp, STR_BOUNDS(MAX_CMDLINE));
+				found = cmdtab_compl(tmp, STR_BOUNDS(MAX_CMDLINE), indev);
 			} else {
 				/* Symbol completion */
-				found = symtab_compl(tmp, STR_BOUNDS(MAX_CMDLINE));
+				found = symtab_compl(tmp, STR_BOUNDS(MAX_CMDLINE), indev);
 			}
 			
 			if (found == 0)
 				continue;
-			
-			if (found > 1) {
-				/* No unique hint, list was printed */
-				printf("%s> ", prompt);
-				printf("%ls", current);
-				print_cc('\b', wstr_length(current) - position);
-				continue;
-			}
-			
-			/* We have a hint */
-			
+
+			/* We have hints, may be many. In case of more than one hint,
+			   tmp will contain the common prefix. */
 			size_t off = 0;
 			size_t i = 0;
@@ -320,4 +342,15 @@
 				i++;
 			}
+			
+			if (found > 1) {
+				/* No unique hint, list was printed */
+				printf("%s> ", prompt);
+				printf("%ls", current);
+				position += str_length(tmp);
+				print_cc('\b', wstr_length(current) - position);
+				continue;
+			}
+			
+			/* We have a hint */
 			
 			printf("%ls", current + position);
@@ -540,5 +573,5 @@
 /** Parse command line.
  *
- * @param cmdline Command line as read from input device. 
+ * @param cmdline Command line as read from input device.
  * @param size    Size (in bytes) of the string.
  *
Index: kernel/generic/src/console/prompt.c
===================================================================
--- kernel/generic/src/console/prompt.c	(revision 97c76825acca82d15cb8daa0e50df4f66ffd6c0b)
+++ kernel/generic/src/console/prompt.c	(revision 97c76825acca82d15cb8daa0e50df4f66ffd6c0b)
@@ -0,0 +1,116 @@
+/*
+ * Copyright (c) 2012 Sandeep Kumar
+ * Copyright (c) 2012 Vojtech Horky
+ * 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 genericconsole
+ * @{
+ */
+
+/**
+ * @file
+ * @brief Kernel console special prompts.
+ */
+
+#include <console/prompt.h>
+
+/** Display the <i>display all possibilities</i> prompt and wait for answer.
+ *
+ * @param indev Where to read characters from.
+ * @param hints Number of hints that would be displayed.
+ * @return Whether to print all hints.
+ */
+bool console_prompt_display_all_hints(indev_t *indev, size_t hints)
+{
+	ASSERT(indev);
+	ASSERT(hints > 0);
+
+	printf("Display all %zu possibilities? (y or n)", hints);
+
+	while (true) {
+		wchar_t answer = indev_pop_character(indev);
+
+		if (answer == 'y' || answer == 'Y') {
+			printf(" y");
+			return true;
+		}
+
+		if (answer == 'n' || answer == 'N') {
+			printf(" n");
+			return false;
+		}
+	}
+}
+
+/** Display the <i>--more--</i> prompt and wait for answer.
+ *
+ * When the function returns false, @p display_hints is set to zero.
+ *
+ * @param[in] indev Where to read characters from.
+ * @param[out] display_hints How many hints to display.
+ * @return Whether to display more hints.
+ */
+bool console_prompt_more_hints(indev_t *indev, size_t *display_hints)
+{
+	ASSERT(indev);
+	ASSERT(display_hints != NULL);
+
+	printf("--More--");
+	while (true) {
+		wchar_t continue_showing_hints = indev_pop_character(indev);
+		/* Display a full page again? */
+		if (continue_showing_hints == 'y'
+		    || continue_showing_hints == 'Y'
+		    || continue_showing_hints == ' ') {
+			*display_hints = MAX_TAB_HINTS - 1;
+			break;
+		}
+
+		/* Stop displaying hints? */
+		if (continue_showing_hints == 'n'
+		    || continue_showing_hints == 'N'
+		    || continue_showing_hints == 'q'
+		    || continue_showing_hints == 'Q') {
+			*display_hints = 0;
+			break;
+		}
+
+		/* Show one more hint? */
+		if (continue_showing_hints == '\n') {
+			*display_hints = 1;
+			break;
+		}
+	}
+
+	/* Delete the --More-- option */
+	printf("\r         \r");
+
+	return *display_hints > 0;
+}
+
+/** @}
+ */
Index: kernel/generic/src/debug/symtab.c
===================================================================
--- kernel/generic/src/debug/symtab.c	(revision 0747468d84f2b1c59f16a0b00b33c12aa2a95e3f)
+++ kernel/generic/src/debug/symtab.c	(revision 97c76825acca82d15cb8daa0e50df4f66ffd6c0b)
@@ -43,4 +43,5 @@
 #include <typedefs.h>
 #include <errno.h>
+#include <console/prompt.h>
 
 /** Get name of a symbol that seems most likely to correspond to address.
@@ -209,5 +210,5 @@
  *
  */
-int symtab_compl(char *input, size_t size)
+int symtab_compl(char *input, size_t size, indev_t * indev)
 {
 #ifdef CONFIG_SYMTAB
@@ -226,6 +227,21 @@
 	const char *hint;
 	char output[MAX_SYMBOL_NAME];
+	/* Maximum Match Length : Length of longest matching common substring in
+	   case more than one match is found */
+	size_t max_match_len = size;
+	size_t max_match_len_tmp = size;
+	size_t input_len = str_length(input);
+	char *sym_name;
+	size_t hints_to_show = MAX_TAB_HINTS - 1;
+	size_t total_hints_shown = 0;
+	bool continue_showing_hints = true;
 	
 	output[0] = 0;
+
+	while ((hint = symtab_search_one(name, &pos))) {
+		++pos;
+	}
+
+	pos = 0;
 	
 	while ((hint = symtab_search_one(name, &pos))) {
@@ -235,4 +251,10 @@
 		pos++;
 		found++;
+	}
+	
+	/* If possible completions are more than MAX_TAB_HINTS, ask user whether to display them or not. */
+	if (found > MAX_TAB_HINTS) {
+		printf("\n");
+		continue_showing_hints = console_prompt_display_all_hints(indev, found);
 	}
 	
@@ -241,7 +263,23 @@
 		pos = 0;
 		while (symtab_search_one(name, &pos)) {
-			printf("%s\n", symbol_table[pos].symbol_name);
+			sym_name = symbol_table[pos].symbol_name;
 			pos++;
+
+			if (continue_showing_hints) { /* We are still showing hints */
+				printf("%s\n", sym_name);
+				--hints_to_show;
+				++total_hints_shown;
+
+				if (hints_to_show == 0 && total_hints_shown != found) { /* Time to ask user to continue */
+					continue_showing_hints = console_prompt_more_hints(indev, &hints_to_show);
+				}
+			}
+
+			for(max_match_len_tmp = 0; output[max_match_len_tmp] == sym_name[input_len + max_match_len_tmp]
+					&& max_match_len_tmp < max_match_len; ++max_match_len_tmp);
+			max_match_len = max_match_len_tmp;
 		}
+		/* keep only the characters common in all completions */
+		output[max_match_len] = 0;
 	}
 	
Index: kernel/generic/src/ipc/ipc.c
===================================================================
--- kernel/generic/src/ipc/ipc.c	(revision 0747468d84f2b1c59f16a0b00b33c12aa2a95e3f)
+++ kernel/generic/src/ipc/ipc.c	(revision 97c76825acca82d15cb8daa0e50df4f66ffd6c0b)
@@ -670,7 +670,7 @@
 void ipc_init(void)
 {
-	ipc_call_slab = slab_cache_create("ipc_call", sizeof(call_t), 0, NULL,
+	ipc_call_slab = slab_cache_create("call_t", sizeof(call_t), 0, NULL,
 	    NULL, 0);
-	ipc_answerbox_slab = slab_cache_create("ipc_answerbox",
+	ipc_answerbox_slab = slab_cache_create("answerbox_t",
 	    sizeof(answerbox_t), 0, NULL, NULL, 0);
 }
Index: kernel/generic/src/ipc/kbox.c
===================================================================
--- kernel/generic/src/ipc/kbox.c	(revision 0747468d84f2b1c59f16a0b00b33c12aa2a95e3f)
+++ kernel/generic/src/ipc/kbox.c	(revision 97c76825acca82d15cb8daa0e50df4f66ffd6c0b)
@@ -244,6 +244,6 @@
 	
 	/* Create a kbox thread */
-	thread_t *kb_thread = thread_create(kbox_thread_proc, NULL, task, 0,
-	    "kbox", false);
+	thread_t *kb_thread = thread_create(kbox_thread_proc, NULL, task,
+	    THREAD_FLAG_NONE, "kbox");
 	if (!kb_thread) {
 		mutex_unlock(&task->kb.cleanup_lock);
Index: kernel/generic/src/ipc/sysipc.c
===================================================================
--- kernel/generic/src/ipc/sysipc.c	(revision 0747468d84f2b1c59f16a0b00b33c12aa2a95e3f)
+++ kernel/generic/src/ipc/sysipc.c	(revision 97c76825acca82d15cb8daa0e50df4f66ffd6c0b)
@@ -111,5 +111,5 @@
 	switch (imethod) {
 	case IPC_M_CONNECTION_CLONE:
-	case IPC_M_CONNECT_ME:
+	case IPC_M_CLONE_ESTABLISH:
 	case IPC_M_PHONE_HUNGUP:
 		/* This message is meant only for the original recipient. */
@@ -160,5 +160,5 @@
 	switch (IPC_GET_IMETHOD(call->data)) {
 	case IPC_M_CONNECTION_CLONE:
-	case IPC_M_CONNECT_ME:
+	case IPC_M_CLONE_ESTABLISH:
 	case IPC_M_CONNECT_TO_ME:
 	case IPC_M_CONNECT_ME_TO:
@@ -225,5 +225,5 @@
 			mutex_unlock(&phone->lock);
 		}
-	} else if (IPC_GET_IMETHOD(*olddata) == IPC_M_CONNECT_ME) {
+	} else if (IPC_GET_IMETHOD(*olddata) == IPC_M_CLONE_ESTABLISH) {
 		phone_t *phone = (phone_t *) IPC_GET_ARG5(*olddata);
 		
@@ -459,5 +459,5 @@
 		break;
 	}
-	case IPC_M_CONNECT_ME:
+	case IPC_M_CLONE_ESTABLISH:
 		IPC_SET_ARG5(call->data, (sysarg_t) phone);
 		break;
@@ -597,5 +597,5 @@
 	if (IPC_GET_IMETHOD(call->data) == IPC_M_CONNECT_TO_ME) {
 		int phoneid = phone_alloc(TASK);
-		if (phoneid < 0) { /* Failed to allocate phone */
+		if (phoneid < 0) {  /* Failed to allocate phone */
 			IPC_SET_RETVAL(call->data, ELIMIT);
 			ipc_answer(box, call);
@@ -883,7 +883,7 @@
 	
 	/*
-	 * Userspace is not allowed to change interface and method of system
+	 * User space is not allowed to change interface and method of system
 	 * methods on forward, allow changing ARG1, ARG2, ARG3 and ARG4 by
-	 * means of method, arg1, arg2 and arg3.
+	 * means of imethod, arg1, arg2 and arg3.
 	 * If the interface and method is immutable, don't change anything.
 	 */
@@ -897,11 +897,11 @@
 			IPC_SET_ARG3(call->data, arg2);
 			
-			if (slow) {
+			if (slow)
 				IPC_SET_ARG4(call->data, arg3);
-				/*
-				 * For system methods we deliberately don't
-				 * overwrite ARG5.
-				 */
-			}
+			
+			/*
+			 * For system methods we deliberately don't
+			 * overwrite ARG5.
+			 */
 		} else {
 			IPC_SET_IMETHOD(call->data, imethod);
Index: kernel/generic/src/lib/ra.c
===================================================================
--- kernel/generic/src/lib/ra.c	(revision 0747468d84f2b1c59f16a0b00b33c12aa2a95e3f)
+++ kernel/generic/src/lib/ra.c	(revision 97c76825acca82d15cb8daa0e50df4f66ffd6c0b)
@@ -185,5 +185,5 @@
 		return NULL;
 
-	spinlock_initialize(&arena->lock, "arena_lock");
+	irq_spinlock_initialize(&arena->lock, "arena_lock");
 	list_initialize(&arena->spans);
 
@@ -209,7 +209,7 @@
 
 	/* TODO: check for overlaps */
-	spinlock_lock(&arena->lock);
+	irq_spinlock_lock(&arena->lock, true);
 	list_append(&span->span_link, &arena->spans);
-	spinlock_unlock(&arena->lock);
+	irq_spinlock_unlock(&arena->lock, true);
 	return true;
 }
@@ -390,5 +390,5 @@
 	ASSERT(ispwr2(alignment));
 
-	spinlock_lock(&arena->lock);
+	irq_spinlock_lock(&arena->lock, true);
 	list_foreach(arena->spans, cur) {
 		ra_span_t *span = list_get_instance(cur, ra_span_t, span_link);
@@ -398,5 +398,5 @@
 			break;
 	}
-	spinlock_unlock(&arena->lock);
+	irq_spinlock_unlock(&arena->lock, true);
 
 	return base;
@@ -406,5 +406,5 @@
 void ra_free(ra_arena_t *arena, uintptr_t base, size_t size)
 {
-	spinlock_lock(&arena->lock);
+	irq_spinlock_lock(&arena->lock, true);
 	list_foreach(arena->spans, cur) {
 		ra_span_t *span = list_get_instance(cur, ra_span_t, span_link);
@@ -412,9 +412,9 @@
 		if (iswithin(span->base, span->size, base, size)) {
 			ra_span_free(span, base, size);
-			spinlock_unlock(&arena->lock);
+			irq_spinlock_unlock(&arena->lock, true);
 			return;
 		}
 	}
-	spinlock_unlock(&arena->lock);
+	irq_spinlock_unlock(&arena->lock, true);
 
 	panic("Freeing to wrong arena (base=%" PRIxn ", size=%" PRIdn ").",
@@ -424,5 +424,5 @@
 void ra_init(void)
 {
-	ra_segment_cache = slab_cache_create("segment_cache",
+	ra_segment_cache = slab_cache_create("ra_segment_t",
 	    sizeof(ra_segment_t), 0, NULL, NULL, SLAB_CACHE_MAGDEFERRED);
 }
Index: kernel/generic/src/lib/rd.c
===================================================================
--- kernel/generic/src/lib/rd.c	(revision 0747468d84f2b1c59f16a0b00b33c12aa2a95e3f)
+++ kernel/generic/src/lib/rd.c	(revision 97c76825acca82d15cb8daa0e50df4f66ffd6c0b)
@@ -38,4 +38,5 @@
  */
 
+#include <print.h>
 #include <lib/rd.h>
 #include <mm/frame.h>
@@ -66,4 +67,6 @@
 	sysinfo_set_item_val("rd.size", NULL, size);
 	sysinfo_set_item_val("rd.address.physical", NULL, (sysarg_t) base);
+	
+	printf("RAM disk at %p (size %zu bytes)\n", (void *) base, size);
 }
 
Index: kernel/generic/src/main/kinit.c
===================================================================
--- kernel/generic/src/main/kinit.c	(revision 0747468d84f2b1c59f16a0b00b33c12aa2a95e3f)
+++ kernel/generic/src/main/kinit.c	(revision 97c76825acca82d15cb8daa0e50df4f66ffd6c0b)
@@ -116,9 +116,8 @@
 		 * Just a beautification.
 		 */
-		thread = thread_create(kmp, NULL, TASK, THREAD_FLAG_WIRED, "kmp", true);
+		thread = thread_create(kmp, NULL, TASK,
+		    THREAD_FLAG_UNCOUNTED, "kmp");
 		if (thread != NULL) {
-			irq_spinlock_lock(&thread->lock, false);
-			thread->cpu = &cpus[0];
-			irq_spinlock_unlock(&thread->lock, false);
+			thread_wire(thread, &cpus[0]);
 			thread_ready(thread);
 		} else
@@ -134,9 +133,8 @@
 		
 		for (i = 0; i < config.cpu_count; i++) {
-			thread = thread_create(kcpulb, NULL, TASK, THREAD_FLAG_WIRED, "kcpulb", true);
+			thread = thread_create(kcpulb, NULL, TASK,
+			    THREAD_FLAG_UNCOUNTED, "kcpulb");
 			if (thread != NULL) {
-				irq_spinlock_lock(&thread->lock, false);
-				thread->cpu = &cpus[i];
-				irq_spinlock_unlock(&thread->lock, false);
+				thread_wire(thread, &cpus[i]);
 				thread_ready(thread);
 			} else
@@ -152,5 +150,6 @@
 	
 	/* Start thread computing system load */
-	thread = thread_create(kload, NULL, TASK, 0, "kload", false);
+	thread = thread_create(kload, NULL, TASK, THREAD_FLAG_NONE,
+	    "kload");
 	if (thread != NULL)
 		thread_ready(thread);
@@ -163,5 +162,6 @@
 		 * Create kernel console.
 		 */
-		thread = thread_create(kconsole_thread, NULL, TASK, 0, "kconsole", false);
+		thread = thread_create(kconsole_thread, NULL, TASK,
+		    THREAD_FLAG_NONE, "kconsole");
 		if (thread != NULL)
 			thread_ready(thread);
@@ -201,5 +201,5 @@
 		str_cpy(namebuf + INIT_PREFIX_LEN,
 		    TASK_NAME_BUFLEN - INIT_PREFIX_LEN, name);
-
+		
 		/*
 		 * Create virtual memory mappings for init task images.
@@ -236,5 +236,7 @@
 			init_rd((void *) init.tasks[i].paddr, init.tasks[i].size);
 		} else
-			printf("init[%zu]: Init binary load failed (error %d)\n", i, rc);
+			printf("init[%zu]: Init binary load failed "
+			    "(error %d, loader status %u)\n", i, rc,
+			    programs[i].loader_status);
 	}
 	
Index: kernel/generic/src/main/main.c
===================================================================
--- kernel/generic/src/main/main.c	(revision 0747468d84f2b1c59f16a0b00b33c12aa2a95e3f)
+++ kernel/generic/src/main/main.c	(revision 97c76825acca82d15cb8daa0e50df4f66ffd6c0b)
@@ -276,6 +276,6 @@
 	 * Create the first thread.
 	 */
-	thread_t *kinit_thread =
-	    thread_create(kinit, NULL, kernel, 0, "kinit", true);
+	thread_t *kinit_thread = thread_create(kinit, NULL, kernel,
+	    THREAD_FLAG_UNCOUNTED, "kinit");
 	if (!kinit_thread)
 		panic("Cannot create kinit thread.");
Index: kernel/generic/src/main/uinit.c
===================================================================
--- kernel/generic/src/main/uinit.c	(revision 0747468d84f2b1c59f16a0b00b33c12aa2a95e3f)
+++ kernel/generic/src/main/uinit.c	(revision 97c76825acca82d15cb8daa0e50df4f66ffd6c0b)
@@ -56,6 +56,4 @@
 void uinit(void *arg)
 {
-	uspace_arg_t uarg;
-	
 	/*
 	 * So far, we don't have a use for joining userspace threads so we
@@ -72,13 +70,17 @@
 #endif
 	
-	uarg.uspace_entry = ((uspace_arg_t *) arg)->uspace_entry;
-	uarg.uspace_stack = ((uspace_arg_t *) arg)->uspace_stack;
-	uarg.uspace_uarg = ((uspace_arg_t *) arg)->uspace_uarg;
-	uarg.uspace_thread_function = NULL;
-	uarg.uspace_thread_arg = NULL;
+	uspace_arg_t *uarg = (uspace_arg_t *) arg;
+	uspace_arg_t local_uarg;
 	
-	free((uspace_arg_t *) arg);
+	local_uarg.uspace_entry = uarg->uspace_entry;
+	local_uarg.uspace_stack = uarg->uspace_stack;
+	local_uarg.uspace_stack_size = uarg->uspace_stack_size;
+	local_uarg.uspace_uarg = uarg->uspace_uarg;
+	local_uarg.uspace_thread_function = NULL;
+	local_uarg.uspace_thread_arg = NULL;
 	
-	userspace(&uarg);
+	free(uarg);
+	
+	userspace(&local_uarg);
 }
 
Index: kernel/generic/src/mm/as.c
===================================================================
--- kernel/generic/src/mm/as.c	(revision 0747468d84f2b1c59f16a0b00b33c12aa2a95e3f)
+++ kernel/generic/src/mm/as.c	(revision 97c76825acca82d15cb8daa0e50df4f66ffd6c0b)
@@ -130,5 +130,5 @@
 	as_arch_init();
 	
-	as_slab = slab_cache_create("as_slab", sizeof(as_t), 0,
+	as_slab = slab_cache_create("as_t", sizeof(as_t), 0,
 	    as_constructor, as_destructor, SLAB_CACHE_MAGDEFERRED);
 	
@@ -665,10 +665,4 @@
 		
 		page_table_lock(as, false);
-		
-		/*
-		 * Start TLB shootdown sequence.
-		 */
-		ipl_t ipl = tlb_shootdown_start(TLB_INVL_PAGES, as->asid,
-		    area->base + P2SZ(pages), area->pages - pages);
 		
 		/*
@@ -726,4 +720,20 @@
 				}
 				
+				/*
+				 * Start TLB shootdown sequence.
+				 *
+				 * The sequence is rather short and can be
+				 * repeated multiple times. The reason is that
+				 * we don't want to have used_space_remove()
+				 * inside the sequence as it may use a blocking
+				 * memory allocation for its B+tree. Blocking
+				 * while holding the tlblock spinlock is
+				 * forbidden and would hit a kernel assertion.
+				 */
+
+				ipl_t ipl = tlb_shootdown_start(TLB_INVL_PAGES,
+				    as->asid, area->base + P2SZ(pages),
+				    area->pages - pages);
+		
 				for (; i < size; i++) {
 					pte_t *pte = page_mapping_find(as,
@@ -743,22 +753,23 @@
 					page_mapping_remove(as, ptr + P2SZ(i));
 				}
+		
+				/*
+				 * Finish TLB shootdown sequence.
+				 */
+		
+				tlb_invalidate_pages(as->asid,
+				    area->base + P2SZ(pages),
+				    area->pages - pages);
+		
+				/*
+				 * Invalidate software translation caches
+				 * (e.g. TSB on sparc64, PHT on ppc32).
+				 */
+				as_invalidate_translation_cache(as,
+				    area->base + P2SZ(pages),
+				    area->pages - pages);
+				tlb_shootdown_finalize(ipl);
 			}
 		}
-		
-		/*
-		 * Finish TLB shootdown sequence.
-		 */
-		
-		tlb_invalidate_pages(as->asid, area->base + P2SZ(pages),
-		    area->pages - pages);
-		
-		/*
-		 * Invalidate software translation caches
-		 * (e.g. TSB on sparc64, PHT on ppc32).
-		 */
-		as_invalidate_translation_cache(as, area->base + P2SZ(pages),
-		    area->pages - pages);
-		tlb_shootdown_finalize(ipl);
-		
 		page_table_unlock(as, false);
 	} else {
Index: kernel/generic/src/mm/frame.c
===================================================================
--- kernel/generic/src/mm/frame.c	(revision 0747468d84f2b1c59f16a0b00b33c12aa2a95e3f)
+++ kernel/generic/src/mm/frame.c	(revision 97c76825acca82d15cb8daa0e50df4f66ffd6c0b)
@@ -1086,4 +1086,9 @@
 #endif
 		
+		/*
+		 * Since the mem_avail_mtx is an active mutex, we need to disable interrupts
+		 * to prevent deadlock with TLB shootdown.
+		 */
+		ipl_t ipl = interrupts_disable();
 		mutex_lock(&mem_avail_mtx);
 		
@@ -1098,4 +1103,5 @@
 		
 		mutex_unlock(&mem_avail_mtx);
+		interrupts_restore(ipl);
 		
 #ifdef CONFIG_DEBUG
@@ -1161,4 +1167,11 @@
 	 * Signal that some memory has been freed.
 	 */
+
+	
+	/*
+	 * Since the mem_avail_mtx is an active mutex, we need to disable interrupts
+	 * to prevent deadlock with TLB shootdown.
+	 */
+	ipl_t ipl = interrupts_disable();
 	mutex_lock(&mem_avail_mtx);
 	if (mem_avail_req > 0)
@@ -1170,4 +1183,5 @@
 	}
 	mutex_unlock(&mem_avail_mtx);
+	interrupts_restore(ipl);
 	
 	if (!(flags & FRAME_NO_RESERVE))
Index: kernel/generic/src/mm/slab.c
===================================================================
--- kernel/generic/src/mm/slab.c	(revision 0747468d84f2b1c59f16a0b00b33c12aa2a95e3f)
+++ kernel/generic/src/mm/slab.c	(revision 97c76825acca82d15cb8daa0e50df4f66ffd6c0b)
@@ -264,5 +264,5 @@
 		freed = cache->destructor(obj);
 	
-	spinlock_lock(&cache->slablock);
+	irq_spinlock_lock(&cache->slablock, true);
 	ASSERT(slab->available < cache->objects);
 	
@@ -275,5 +275,5 @@
 		/* Free associated memory */
 		list_remove(&slab->link);
-		spinlock_unlock(&cache->slablock);
+		irq_spinlock_unlock(&cache->slablock, true);
 		
 		return freed + slab_space_free(cache, slab);
@@ -284,5 +284,5 @@
 	}
 	
-	spinlock_unlock(&cache->slablock);
+	irq_spinlock_unlock(&cache->slablock, true);
 	return freed;
 }
@@ -295,5 +295,5 @@
 NO_TRACE static void *slab_obj_create(slab_cache_t *cache, unsigned int flags)
 {
-	spinlock_lock(&cache->slablock);
+	irq_spinlock_lock(&cache->slablock, true);
 	
 	slab_t *slab;
@@ -308,10 +308,10 @@
 		 *
 		 */
-		spinlock_unlock(&cache->slablock);
+		irq_spinlock_unlock(&cache->slablock, true);
 		slab = slab_space_alloc(cache, flags);
 		if (!slab)
 			return NULL;
 		
-		spinlock_lock(&cache->slablock);
+		irq_spinlock_lock(&cache->slablock, true);
 	} else {
 		slab = list_get_instance(list_first(&cache->partial_slabs),
@@ -329,5 +329,5 @@
 		list_prepend(&slab->link, &cache->partial_slabs);
 	
-	spinlock_unlock(&cache->slablock);
+	irq_spinlock_unlock(&cache->slablock, true);
 	
 	if ((cache->constructor) && (cache->constructor(obj, flags))) {
@@ -355,5 +355,5 @@
 	link_t *cur;
 	
-	spinlock_lock(&cache->maglock);
+	irq_spinlock_lock(&cache->maglock, true);
 	if (!list_empty(&cache->magazines)) {
 		if (first)
@@ -366,6 +366,6 @@
 		atomic_dec(&cache->magazine_counter);
 	}
-	
-	spinlock_unlock(&cache->maglock);
+	irq_spinlock_unlock(&cache->maglock, true);
+
 	return mag;
 }
@@ -377,10 +377,10 @@
     slab_magazine_t *mag)
 {
-	spinlock_lock(&cache->maglock);
+	irq_spinlock_lock(&cache->maglock, true);
 	
 	list_prepend(&mag->link, &cache->magazines);
 	atomic_inc(&cache->magazine_counter);
 	
-	spinlock_unlock(&cache->maglock);
+	irq_spinlock_unlock(&cache->maglock, true);
 }
 
@@ -414,5 +414,5 @@
 	slab_magazine_t *lastmag = cache->mag_cache[CPU->id].last;
 	
-	ASSERT(spinlock_locked(&cache->mag_cache[CPU->id].lock));
+	ASSERT(irq_spinlock_locked(&cache->mag_cache[CPU->id].lock));
 	
 	if (cmag) { /* First try local CPU magazines */
@@ -451,14 +451,14 @@
 		return NULL;
 	
-	spinlock_lock(&cache->mag_cache[CPU->id].lock);
+	irq_spinlock_lock(&cache->mag_cache[CPU->id].lock, true);
 	
 	slab_magazine_t *mag = get_full_current_mag(cache);
 	if (!mag) {
-		spinlock_unlock(&cache->mag_cache[CPU->id].lock);
+		irq_spinlock_unlock(&cache->mag_cache[CPU->id].lock, true);
 		return NULL;
 	}
 	
 	void *obj = mag->objs[--mag->busy];
-	spinlock_unlock(&cache->mag_cache[CPU->id].lock);
+	irq_spinlock_unlock(&cache->mag_cache[CPU->id].lock, true);
 	
 	atomic_dec(&cache->cached_objs);
@@ -481,5 +481,5 @@
 	slab_magazine_t *lastmag = cache->mag_cache[CPU->id].last;
 	
-	ASSERT(spinlock_locked(&cache->mag_cache[CPU->id].lock));
+	ASSERT(irq_spinlock_locked(&cache->mag_cache[CPU->id].lock));
 	
 	if (cmag) {
@@ -531,9 +531,9 @@
 		return -1;
 	
-	spinlock_lock(&cache->mag_cache[CPU->id].lock);
+	irq_spinlock_lock(&cache->mag_cache[CPU->id].lock, true);
 	
 	slab_magazine_t *mag = make_empty_current_mag(cache);
 	if (!mag) {
-		spinlock_unlock(&cache->mag_cache[CPU->id].lock);
+		irq_spinlock_unlock(&cache->mag_cache[CPU->id].lock, true);
 		return -1;
 	}
@@ -541,5 +541,5 @@
 	mag->objs[mag->busy++] = obj;
 	
-	spinlock_unlock(&cache->mag_cache[CPU->id].lock);
+	irq_spinlock_unlock(&cache->mag_cache[CPU->id].lock, true);
 	
 	atomic_inc(&cache->cached_objs);
@@ -593,5 +593,5 @@
 	for (i = 0; i < config.cpu_count; i++) {
 		memsetb(&cache->mag_cache[i], sizeof(cache->mag_cache[i]), 0);
-		spinlock_initialize(&cache->mag_cache[i].lock,
+		irq_spinlock_initialize(&cache->mag_cache[i].lock,
 		    "slab.cache.mag_cache[].lock");
 	}
@@ -624,6 +624,6 @@
 	list_initialize(&cache->magazines);
 	
-	spinlock_initialize(&cache->slablock, "slab.cache.slablock");
-	spinlock_initialize(&cache->maglock, "slab.cache.maglock");
+	irq_spinlock_initialize(&cache->slablock, "slab.cache.slablock");
+	irq_spinlock_initialize(&cache->maglock, "slab.cache.maglock");
 	
 	if (!(cache->flags & SLAB_CACHE_NOMAGAZINE))
@@ -704,5 +704,5 @@
 		size_t i;
 		for (i = 0; i < config.cpu_count; i++) {
-			spinlock_lock(&cache->mag_cache[i].lock);
+			irq_spinlock_lock(&cache->mag_cache[i].lock, true);
 			
 			mag = cache->mag_cache[i].current;
@@ -716,5 +716,5 @@
 			cache->mag_cache[i].last = NULL;
 			
-			spinlock_unlock(&cache->mag_cache[i].lock);
+			irq_spinlock_unlock(&cache->mag_cache[i].lock, true);
 		}
 	}
@@ -891,5 +891,5 @@
 {
 	/* Initialize magazine cache */
-	_slab_cache_create(&mag_cache, "slab_magazine",
+	_slab_cache_create(&mag_cache, "slab_magazine_t",
 	    sizeof(slab_magazine_t) + SLAB_MAG_SIZE * sizeof(void*),
 	    sizeof(uintptr_t), NULL, NULL, SLAB_CACHE_NOMAGAZINE |
@@ -897,10 +897,10 @@
 	
 	/* Initialize slab_cache cache */
-	_slab_cache_create(&slab_cache_cache, "slab_cache",
+	_slab_cache_create(&slab_cache_cache, "slab_cache_cache",
 	    sizeof(slab_cache_cache), sizeof(uintptr_t), NULL, NULL,
 	    SLAB_CACHE_NOMAGAZINE | SLAB_CACHE_SLINSIDE);
 	
 	/* Initialize external slab cache */
-	slab_extern_cache = slab_cache_create("slab_extern", sizeof(slab_t), 0,
+	slab_extern_cache = slab_cache_create("slab_t", sizeof(slab_t), 0,
 	    NULL, NULL, SLAB_CACHE_SLINSIDE | SLAB_CACHE_MAGDEFERRED);
 	
Index: kernel/generic/src/mm/tlb.c
===================================================================
--- kernel/generic/src/mm/tlb.c	(revision 0747468d84f2b1c59f16a0b00b33c12aa2a95e3f)
+++ kernel/generic/src/mm/tlb.c	(revision 97c76825acca82d15cb8daa0e50df4f66ffd6c0b)
@@ -162,5 +162,5 @@
 	
 	size_t i;
-	for (i = 0; i < CPU->tlb_messages_count; CPU->tlb_messages_count--) {
+	for (i = 0; i < CPU->tlb_messages_count; i++) {
 		tlb_invalidate_type_t type = CPU->tlb_messages[i].type;
 		asid_t asid = CPU->tlb_messages[i].asid;
@@ -188,4 +188,5 @@
 	}
 	
+	CPU->tlb_messages_count = 0;
 	irq_spinlock_unlock(&CPU->lock, false);
 	CPU->tlb_active = true;
Index: kernel/generic/src/printf/printf_core.c
===================================================================
--- kernel/generic/src/printf/printf_core.c	(revision 0747468d84f2b1c59f16a0b00b33c12aa2a95e3f)
+++ kernel/generic/src/printf/printf_core.c	(revision 97c76825acca82d15cb8daa0e50df4f66ffd6c0b)
@@ -284,5 +284,5 @@
 	/* Print leading spaces. */
 	size_t strw = str_length(str);
-	if (precision == 0)
+	if ((precision == 0) || (precision > strw))
 		precision = strw;
 	
@@ -332,5 +332,5 @@
 	/* Print leading spaces. */
 	size_t strw = wstr_length(str);
-	if (precision == 0)
+	if ((precision == 0) || (precision > strw))
 		precision = strw;
 	
Index: kernel/generic/src/proc/program.c
===================================================================
--- kernel/generic/src/proc/program.c	(revision 0747468d84f2b1c59f16a0b00b33c12aa2a95e3f)
+++ kernel/generic/src/proc/program.c	(revision 97c76825acca82d15cb8daa0e50df4f66ffd6c0b)
@@ -71,13 +71,5 @@
 int program_create(as_t *as, uintptr_t entry_addr, char *name, program_t *prg)
 {
-	uspace_arg_t *kernel_uarg;
-	
-	kernel_uarg = (uspace_arg_t *) malloc(sizeof(uspace_arg_t), 0);
-	kernel_uarg->uspace_entry = (void *) entry_addr;
-	kernel_uarg->uspace_stack = (void *) USTACK_ADDRESS;
-	kernel_uarg->uspace_thread_function = NULL;
-	kernel_uarg->uspace_thread_arg = NULL;
-	kernel_uarg->uspace_uarg = NULL;
-	
+	prg->loader_status = EE_OK;
 	prg->task = task_create(as, name);
 	if (!prg->task)
@@ -91,6 +83,18 @@
 	    AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE,
 	    STACK_SIZE, AS_AREA_ATTR_NONE, &anon_backend, NULL, &virt, 0);
-	if (!area)
+	if (!area) {
+		task_destroy(prg->task);
 		return ENOMEM;
+	}
+	
+	uspace_arg_t *kernel_uarg = (uspace_arg_t *)
+	    malloc(sizeof(uspace_arg_t), 0);
+	
+	kernel_uarg->uspace_entry = (void *) entry_addr;
+	kernel_uarg->uspace_stack = (void *) virt;
+	kernel_uarg->uspace_stack_size = STACK_SIZE;
+	kernel_uarg->uspace_thread_function = NULL;
+	kernel_uarg->uspace_thread_arg = NULL;
+	kernel_uarg->uspace_uarg = NULL;
 	
 	/*
@@ -98,7 +102,11 @@
 	 */
 	prg->main_thread = thread_create(uinit, kernel_uarg, prg->task,
-	    THREAD_FLAG_USPACE, "uinit", false);
-	if (!prg->main_thread)
+	    THREAD_FLAG_USPACE, "uinit");
+	if (!prg->main_thread) {
+		free(kernel_uarg);
+		as_area_destroy(as, virt);
+		task_destroy(prg->task);
 		return ELIMIT;
+	}
 	
 	return EOK;
@@ -111,9 +119,10 @@
  * executable image. The task is returned in *task.
  *
- * @param image_addr Address of an executable program image.
- * @param name       Name to set for the program's task.
- * @param prg        Buffer for storing program info. If image_addr
- *                   points to a loader image, p->task will be set to
- *                   NULL and EOK will be returned.
+ * @param[in]  image_addr Address of an executable program image.
+ * @param[in]  name       Name to set for the program's task.
+ * @param[out] prg        Buffer for storing program info.
+ *                        If image_addr points to a loader image,
+ *                        prg->task will be set to NULL and EOK
+ *                        will be returned.
  *
  * @return EOK on success or negative error code.
@@ -126,11 +135,11 @@
 		return ENOMEM;
 	
-	unsigned int rc = elf_load((elf_header_t *) image_addr, as, 0);
-	if (rc != EE_OK) {
+	prg->loader_status = elf_load((elf_header_t *) image_addr, as, 0);
+	if (prg->loader_status != EE_OK) {
 		as_destroy(as);
 		prg->task = NULL;
 		prg->main_thread = NULL;
 		
-		if (rc != EE_LOADER)
+		if (prg->loader_status != EE_LOADER)
 			return ENOTSUP;
 		
@@ -140,6 +149,5 @@
 		
 		program_loader = image_addr;
-		LOG("Registered program loader at %p",
-		    (void *) image_addr);
+		printf("Program loader at %p\n", (void *) image_addr);
 		
 		return EOK;
@@ -171,9 +179,10 @@
 	}
 	
-	unsigned int rc = elf_load((elf_header_t *) program_loader, as,
+	prg->loader_status = elf_load((elf_header_t *) program_loader, as,
 	    ELD_F_LOADER);
-	if (rc != EE_OK) {
+	if (prg->loader_status != EE_OK) {
 		as_destroy(as);
-		printf("Cannot spawn loader (%s)\n", elf_error(rc));
+		printf("Cannot spawn loader (%s)\n",
+		    elf_error(prg->loader_status));
 		return ENOENT;
 	}
Index: kernel/generic/src/proc/scheduler.c
===================================================================
--- kernel/generic/src/proc/scheduler.c	(revision 0747468d84f2b1c59f16a0b00b33c12aa2a95e3f)
+++ kernel/generic/src/proc/scheduler.c	(revision 97c76825acca82d15cb8daa0e50df4f66ffd6c0b)
@@ -98,5 +98,5 @@
 	else {
 		fpu_init();
-		THREAD->fpu_context_exists = 1;
+		THREAD->fpu_context_exists = true;
 	}
 #endif
@@ -142,5 +142,5 @@
 		
 		/* Don't prevent migration */
-		CPU->fpu_owner->fpu_context_engaged = 0;
+		CPU->fpu_owner->fpu_context_engaged = false;
 		irq_spinlock_unlock(&CPU->fpu_owner->lock, false);
 		CPU->fpu_owner = NULL;
@@ -163,9 +163,9 @@
 		}
 		fpu_init();
-		THREAD->fpu_context_exists = 1;
+		THREAD->fpu_context_exists = true;
 	}
 	
 	CPU->fpu_owner = THREAD;
-	THREAD->fpu_context_engaged = 1;
+	THREAD->fpu_context_engaged = true;
 	irq_spinlock_unlock(&THREAD->lock, false);
 	
@@ -248,8 +248,8 @@
 		
 		/*
-		 * Clear the THREAD_FLAG_STOLEN flag so that t can be migrated
+		 * Clear the stolen flag so that it can be migrated
 		 * when load balancing needs emerge.
 		 */
-		thread->flags &= ~THREAD_FLAG_STOLEN;
+		thread->stolen = false;
 		irq_spinlock_unlock(&thread->lock, false);
 		
@@ -630,8 +630,7 @@
 				irq_spinlock_lock(&thread->lock, false);
 				
-				if (!(thread->flags & THREAD_FLAG_WIRED) &&
-				    !(thread->flags & THREAD_FLAG_STOLEN) &&
-				    !thread->nomigrate &&
-				    !thread->fpu_context_engaged) {
+				if ((!thread->wired) && (!thread->stolen) &&
+				    (!thread->nomigrate) &&
+				    (!thread->fpu_context_engaged)) {
 					/*
 					 * Remove thread from ready queue.
@@ -670,5 +669,5 @@
 #endif
 				
-				thread->flags |= THREAD_FLAG_STOLEN;
+				thread->stolen = true;
 				thread->state = Entering;
 				
Index: kernel/generic/src/proc/task.c
===================================================================
--- kernel/generic/src/proc/task.c	(revision 0747468d84f2b1c59f16a0b00b33c12aa2a95e3f)
+++ kernel/generic/src/proc/task.c	(revision 97c76825acca82d15cb8daa0e50df4f66ffd6c0b)
@@ -90,5 +90,5 @@
 	TASK = NULL;
 	avltree_create(&tasks_tree);
-	task_slab = slab_cache_create("task_slab", sizeof(task_t), 0,
+	task_slab = slab_cache_create("task_t", sizeof(task_t), 0,
 	    tsk_constructor, NULL, 0);
 }
Index: kernel/generic/src/proc/thread.c
===================================================================
--- kernel/generic/src/proc/thread.c	(revision 0747468d84f2b1c59f16a0b00b33c12aa2a95e3f)
+++ kernel/generic/src/proc/thread.c	(revision 97c76825acca82d15cb8daa0e50df4f66ffd6c0b)
@@ -191,5 +191,5 @@
 	kmflags |= FRAME_LOWMEM;
 	kmflags &= ~FRAME_HIGHMEM;
-
+	
 	thread->kstack = (uint8_t *) frame_alloc(STACK_FRAMES, FRAME_KA | kmflags);
 	if (!thread->kstack) {
@@ -236,10 +236,10 @@
 	
 	atomic_set(&nrdy, 0);
-	thread_slab = slab_cache_create("thread_slab", sizeof(thread_t), 0,
+	thread_slab = slab_cache_create("thread_t", sizeof(thread_t), 0,
 	    thr_constructor, thr_destructor, 0);
 	
 #ifdef CONFIG_FPU
-	fpu_context_slab = slab_cache_create("fpu_slab", sizeof(fpu_context_t),
-	    FPU_CONTEXT_ALIGN, NULL, NULL, 0);
+	fpu_context_slab = slab_cache_create("fpu_context_t",
+	    sizeof(fpu_context_t), FPU_CONTEXT_ALIGN, NULL, NULL, 0);
 #endif
 	
@@ -247,4 +247,17 @@
 }
 
+/** Wire thread to the given CPU
+ *
+ * @param cpu CPU to wire the thread to.
+ *
+ */
+void thread_wire(thread_t *thread, cpu_t *cpu)
+{
+	irq_spinlock_lock(&thread->lock, true);
+	thread->cpu = cpu;
+	thread->wired = true;
+	irq_spinlock_unlock(&thread->lock, true);
+}
+
 /** Make thread ready
  *
@@ -260,12 +273,14 @@
 	ASSERT(thread->state != Ready);
 	
-	int i = (thread->priority < RQ_COUNT - 1)
-	    ? ++thread->priority : thread->priority;
-	
-	cpu_t *cpu = CPU;
-	if (thread->flags & THREAD_FLAG_WIRED) {
+	int i = (thread->priority < RQ_COUNT - 1) ?
+	    ++thread->priority : thread->priority;
+	
+	cpu_t *cpu;
+	if (thread->wired || thread->nomigrate || thread->fpu_context_engaged) {
 		ASSERT(thread->cpu != NULL);
 		cpu = thread->cpu;
-	}
+	} else
+		cpu = CPU;
+	
 	thread->state = Ready;
 	
@@ -298,6 +313,4 @@
  * @param flags     Thread flags.
  * @param name      Symbolic name (a copy is made).
- * @param uncounted Thread's accounting doesn't affect accumulated task
- *                  accounting.
  *
  * @return New thread's structure on success, NULL on failure.
@@ -305,5 +318,5 @@
  */
 thread_t *thread_create(void (* func)(void *), void *arg, task_t *task,
-    unsigned int flags, const char *name, bool uncounted)
+    thread_flags_t flags, const char *name)
 {
 	thread_t *thread = (thread_t *) slab_alloc(thread_slab, 0);
@@ -335,8 +348,13 @@
 	thread->ucycles = 0;
 	thread->kcycles = 0;
-	thread->uncounted = uncounted;
+	thread->uncounted =
+	    ((flags & THREAD_FLAG_UNCOUNTED) == THREAD_FLAG_UNCOUNTED);
 	thread->priority = -1;          /* Start in rq[0] */
 	thread->cpu = NULL;
-	thread->flags = flags;
+	thread->wired = false;
+	thread->stolen = false;
+	thread->uspace =
+	    ((flags & THREAD_FLAG_USPACE) == THREAD_FLAG_USPACE);
+	
 	thread->nomigrate = 0;
 	thread->state = Entering;
@@ -356,6 +374,6 @@
 	thread->task = task;
 	
-	thread->fpu_context_exists = 0;
-	thread->fpu_context_engaged = 0;
+	thread->fpu_context_exists = false;
+	thread->fpu_context_engaged = false;
 	
 	avltree_node_initialize(&thread->threads_tree_node);
@@ -371,5 +389,5 @@
 	thread_create_arch(thread);
 	
-	if (!(flags & THREAD_FLAG_NOATTACH))
+	if ((flags & THREAD_FLAG_NOATTACH) != THREAD_FLAG_NOATTACH)
 		thread_attach(thread, task);
 	
@@ -437,5 +455,5 @@
 	
 	/* Must not count kbox thread into lifecount */
-	if (thread->flags & THREAD_FLAG_USPACE)
+	if (thread->uspace)
 		atomic_inc(&task->lifecount);
 	
@@ -459,9 +477,9 @@
 void thread_exit(void)
 {
-	if (THREAD->flags & THREAD_FLAG_USPACE) {
+	if (THREAD->uspace) {
 #ifdef CONFIG_UDEBUG
 		/* Generate udebug THREAD_E event */
 		udebug_thread_e_event();
-
+		
 		/*
 		 * This thread will not execute any code or system calls from
@@ -506,5 +524,5 @@
 {
 	ASSERT(THREAD);
-
+	
 	THREAD->nomigrate++;
 }
@@ -515,6 +533,7 @@
 	ASSERT(THREAD);
 	ASSERT(THREAD->nomigrate > 0);
-
-	THREAD->nomigrate--;
+	
+	if (THREAD->nomigrate > 0)
+		THREAD->nomigrate--;
 }
 
@@ -854,5 +873,4 @@
 	 * In case of failure, kernel_uarg will be deallocated in this function.
 	 * In case of success, kernel_uarg will be freed in uinit().
-	 *
 	 */
 	uspace_arg_t *kernel_uarg =
@@ -866,5 +884,5 @@
 	
 	thread_t *thread = thread_create(uinit, kernel_uarg, TASK,
-	    THREAD_FLAG_USPACE | THREAD_FLAG_NOATTACH, namebuf, false);
+	    THREAD_FLAG_USPACE | THREAD_FLAG_NOATTACH, namebuf);
 	if (thread) {
 		if (uspace_thread_id != NULL) {
Index: kernel/generic/src/synch/mutex.c
===================================================================
--- kernel/generic/src/synch/mutex.c	(revision 0747468d84f2b1c59f16a0b00b33c12aa2a95e3f)
+++ kernel/generic/src/synch/mutex.c	(revision 97c76825acca82d15cb8daa0e50df4f66ffd6c0b)
@@ -40,4 +40,5 @@
 #include <debug.h>
 #include <arch.h>
+#include <stacktrace.h>
 
 /** Initialize mutex.
@@ -61,4 +62,6 @@
 	return semaphore_count_get(&mtx->sem) <= 0;
 }
+
+#define MUTEX_DEADLOCK_THRESHOLD	100000000
 
 /** Acquire mutex.
@@ -87,8 +90,19 @@
 		ASSERT(!(flags & SYNCH_FLAGS_INTERRUPTIBLE));
 		
+		unsigned int cnt = 0;
+		bool deadlock_reported = false;
 		do {
+			if (cnt++ > MUTEX_DEADLOCK_THRESHOLD) {
+				printf("cpu%u: looping on active mutex %p\n",
+				    CPU->id, mtx);
+				stack_trace();
+				cnt = 0;
+				deadlock_reported = true;
+			}
 			rc = semaphore_trydown(&mtx->sem);
 		} while (SYNCH_FAILED(rc) &&
 		    !(flags & SYNCH_FLAGS_NON_BLOCKING));
+		if (deadlock_reported)
+			printf("cpu%u: not deadlocked\n", CPU->id);
 	}
 
Index: kernel/generic/src/synch/spinlock.c
===================================================================
--- kernel/generic/src/synch/spinlock.c	(revision 0747468d84f2b1c59f16a0b00b33c12aa2a95e3f)
+++ kernel/generic/src/synch/spinlock.c	(revision 97c76825acca82d15cb8daa0e50df4f66ffd6c0b)
@@ -44,4 +44,5 @@
 #include <debug.h>
 #include <symtab.h>
+#include <stacktrace.h>
 
 #ifdef CONFIG_SMP
@@ -104,4 +105,5 @@
 			    "caller=%p (%s)\n", CPU->id, lock, lock->name,
 			    (void *) CALLER, symtab_fmt_name_lookup(CALLER));
+			stack_trace();
 			
 			i = 0;
@@ -260,5 +262,5 @@
 	int rc = spinlock_trylock(&(lock->lock));
 	
-	ASSERT_IRQ_SPINLOCK(!lock->guard, lock);
+	ASSERT_IRQ_SPINLOCK((!rc) || (!lock->guard), lock);
 	return rc;
 }
Index: kernel/generic/src/sysinfo/sysinfo.c
===================================================================
--- kernel/generic/src/sysinfo/sysinfo.c	(revision 0747468d84f2b1c59f16a0b00b33c12aa2a95e3f)
+++ kernel/generic/src/sysinfo/sysinfo.c	(revision 97c76825acca82d15cb8daa0e50df4f66ffd6c0b)
@@ -97,5 +97,5 @@
 void sysinfo_init(void)
 {
-	sysinfo_item_slab = slab_cache_create("sysinfo_item_slab",
+	sysinfo_item_slab = slab_cache_create("sysinfo_item_t",
 	    sizeof(sysinfo_item_t), 0, sysinfo_item_constructor,
 	    sysinfo_item_destructor, SLAB_CACHE_MAGDEFERRED);
Index: kernel/generic/src/udebug/udebug.c
===================================================================
--- kernel/generic/src/udebug/udebug.c	(revision 0747468d84f2b1c59f16a0b00b33c12aa2a95e3f)
+++ kernel/generic/src/udebug/udebug.c	(revision 97c76825acca82d15cb8daa0e50df4f66ffd6c0b)
@@ -410,8 +410,7 @@
 		
 		mutex_lock(&thread->udebug.lock);
-		unsigned int flags = thread->flags;
 		
 		/* Only process userspace threads. */
-		if ((flags & THREAD_FLAG_USPACE) != 0) {
+		if (thread->uspace) {
 			/* Prevent any further debug activity in thread. */
 			thread->udebug.active = false;
Index: kernel/generic/src/udebug/udebug_ops.c
===================================================================
--- kernel/generic/src/udebug/udebug_ops.c	(revision 0747468d84f2b1c59f16a0b00b33c12aa2a95e3f)
+++ kernel/generic/src/udebug/udebug_ops.c	(revision 97c76825acca82d15cb8daa0e50df4f66ffd6c0b)
@@ -95,5 +95,5 @@
 	
 	/* Verify that 'thread' is a userspace thread. */
-	if ((thread->flags & THREAD_FLAG_USPACE) == 0) {
+	if (!thread->uspace) {
 		/* It's not, deny its existence */
 		irq_spinlock_unlock(&thread->lock, true);
@@ -200,5 +200,5 @@
 		
 		mutex_lock(&thread->udebug.lock);
-		if ((thread->flags & THREAD_FLAG_USPACE) != 0) {
+		if (thread->uspace) {
 			thread->udebug.active = true;
 			mutex_unlock(&thread->udebug.lock);
@@ -393,9 +393,9 @@
 		
 		irq_spinlock_lock(&thread->lock, false);
-		int flags = thread->flags;
+		bool uspace = thread->uspace;
 		irq_spinlock_unlock(&thread->lock, false);
 		
 		/* Not interested in kernel threads. */
-		if ((flags & THREAD_FLAG_USPACE) == 0)
+		if (!uspace)
 			continue;
 		
Index: kernel/test/mm/falloc1.c
===================================================================
--- kernel/test/mm/falloc1.c	(revision 0747468d84f2b1c59f16a0b00b33c12aa2a95e3f)
+++ kernel/test/mm/falloc1.c	(revision 97c76825acca82d15cb8daa0e50df4f66ffd6c0b)
@@ -37,32 +37,31 @@
 #include <align.h>
 
-#define MAX_FRAMES  1024
+#define MAX_FRAMES  1024U
 #define MAX_ORDER   8
 #define TEST_RUNS   2
 
-const char *test_falloc1(void) {
-	uintptr_t *frames
-	    = (uintptr_t *) malloc(MAX_FRAMES * sizeof(uintptr_t), 0);
-	int results[MAX_ORDER + 1];
-	
-	int i, order, run;
-	int allocated;
-	
+const char *test_falloc1(void)
+{
 	if (TEST_RUNS < 2)
 		return "Test is compiled with TEST_RUNS < 2";
 	
+	uintptr_t *frames = (uintptr_t *)
+	    malloc(MAX_FRAMES * sizeof(uintptr_t), 0);
 	if (frames == NULL)
 		return "Unable to allocate frames";
 	
-	for (run = 0; run < TEST_RUNS; run++) {
-		for (order = 0; order <= MAX_ORDER; order++) {
-			TPRINTF("Allocating %d frames blocks ... ", 1 << order);
+	unsigned int results[MAX_ORDER + 1];
+	for (unsigned int run = 0; run < TEST_RUNS; run++) {
+		for (unsigned int order = 0; order <= MAX_ORDER; order++) {
+			TPRINTF("Allocating %u frames blocks ... ", 1 << order);
 			
-			allocated = 0;
-			for (i = 0; i < MAX_FRAMES >> order; i++) {
-				frames[allocated] = (uintptr_t) frame_alloc(order, FRAME_ATOMIC | FRAME_KA);
+			unsigned int allocated = 0;
+			for (unsigned int i = 0; i < (MAX_FRAMES >> order); i++) {
+				frames[allocated] = (uintptr_t)
+				    frame_alloc(order, FRAME_ATOMIC | FRAME_KA);
 				
-				if (ALIGN_UP(frames[allocated], FRAME_SIZE << order) != frames[allocated]) {
-					TPRINTF("Block at address %p (size %dK) is not aligned\n",
+				if (ALIGN_UP(frames[allocated], FRAME_SIZE << order) !=
+				    frames[allocated]) {
+					TPRINTF("Block at address %p (size %u) is not aligned\n",
 					    (void *) frames[allocated], (FRAME_SIZE << order) >> 10);
 					return "Test failed";
@@ -87,5 +86,5 @@
 			TPRINTF("Deallocating ... ");
 			
-			for (i = 0; i < allocated; i++)
+			for (unsigned int i = 0; i < allocated; i++)
 				frame_free(KA2PA(frames[i]));
 			
Index: kernel/test/mm/falloc2.c
===================================================================
--- kernel/test/mm/falloc2.c	(revision 0747468d84f2b1c59f16a0b00b33c12aa2a95e3f)
+++ kernel/test/mm/falloc2.c	(revision 97c76825acca82d15cb8daa0e50df4f66ffd6c0b)
@@ -40,5 +40,5 @@
 #include <arch.h>
 
-#define MAX_FRAMES  256
+#define MAX_FRAMES  256U
 #define MAX_ORDER   8
 
@@ -51,11 +51,11 @@
 static void falloc(void *arg)
 {
-	int order, run, allocated, i;
 	uint8_t val = THREAD->tid % THREADS;
-	size_t k;
 	
-	void **frames =  (void **) malloc(MAX_FRAMES * sizeof(void *), FRAME_ATOMIC);
+	void **frames = (void **)
+	    malloc(MAX_FRAMES * sizeof(void *), FRAME_ATOMIC);
 	if (frames == NULL) {
-		TPRINTF("Thread #%" PRIu64 " (cpu%u): Unable to allocate frames\n", THREAD->tid, CPU->id);
+		TPRINTF("Thread #%" PRIu64 " (cpu%u): "
+		    "Unable to allocate frames\n", THREAD->tid, CPU->id);
 		atomic_inc(&thread_fail);
 		atomic_dec(&thread_count);
@@ -65,11 +65,14 @@
 	thread_detach(THREAD);
 	
-	for (run = 0; run < THREAD_RUNS; run++) {
-		for (order = 0; order <= MAX_ORDER; order++) {
-			TPRINTF("Thread #%" PRIu64 " (cpu%u): Allocating %d frames blocks ... \n", THREAD->tid, CPU->id, 1 << order);
+	for (unsigned int run = 0; run < THREAD_RUNS; run++) {
+		for (unsigned int order = 0; order <= MAX_ORDER; order++) {
+			TPRINTF("Thread #%" PRIu64 " (cpu%u): "
+			    "Allocating %u frames blocks ... \n", THREAD->tid,
+			    CPU->id, 1 << order);
 			
-			allocated = 0;
-			for (i = 0; i < (MAX_FRAMES >> order); i++) {
-				frames[allocated] = frame_alloc(order, FRAME_ATOMIC | FRAME_KA);
+			unsigned int allocated = 0;
+			for (unsigned int i = 0; i < (MAX_FRAMES >> order); i++) {
+				frames[allocated] =
+				    frame_alloc(order, FRAME_ATOMIC | FRAME_KA);
 				if (frames[allocated]) {
 					memsetb(frames[allocated], FRAME_SIZE << order, val);
@@ -79,12 +82,18 @@
 			}
 			
-			TPRINTF("Thread #%" PRIu64 " (cpu%u): %d blocks allocated.\n", THREAD->tid, CPU->id, allocated);
-			TPRINTF("Thread #%" PRIu64 " (cpu%u): Deallocating ... \n", THREAD->tid, CPU->id);
+			TPRINTF("Thread #%" PRIu64 " (cpu%u): "
+			    "%u blocks allocated.\n", THREAD->tid, CPU->id,
+			    allocated);
+			TPRINTF("Thread #%" PRIu64 " (cpu%u): "
+			    "Deallocating ... \n", THREAD->tid, CPU->id);
 			
-			for (i = 0; i < allocated; i++) {
-				for (k = 0; k <= (((size_t) FRAME_SIZE << order) - 1); k++) {
+			for (unsigned int i = 0; i < allocated; i++) {
+				for (size_t k = 0; k <= (((size_t) FRAME_SIZE << order) - 1);
+				    k++) {
 					if (((uint8_t *) frames[i])[k] != val) {
-						TPRINTF("Thread #%" PRIu64 " (cpu%u): Unexpected data (%c) in block %p offset %zu\n",
-						    THREAD->tid, CPU->id, ((char *) frames[i])[k], frames[i], k);
+						TPRINTF("Thread #%" PRIu64 " (cpu%u): "
+						    "Unexpected data (%c) in block %p offset %zu\n",
+						    THREAD->tid, CPU->id, ((char *) frames[i])[k],
+						    frames[i], k);
 						atomic_inc(&thread_fail);
 						goto cleanup;
@@ -94,5 +103,6 @@
 			}
 			
-			TPRINTF("Thread #%" PRIu64 " (cpu%u): Finished run.\n", THREAD->tid, CPU->id);
+			TPRINTF("Thread #%" PRIu64 " (cpu%u): "
+			    "Finished run.\n", THREAD->tid, CPU->id);
 		}
 	}
@@ -101,5 +111,6 @@
 	free(frames);
 	
-	TPRINTF("Thread #%" PRIu64 " (cpu%u): Exiting\n", THREAD->tid, CPU->id);
+	TPRINTF("Thread #%" PRIu64 " (cpu%u): Exiting\n",
+	    THREAD->tid, CPU->id);
 	atomic_dec(&thread_count);
 }
@@ -107,11 +118,10 @@
 const char *test_falloc2(void)
 {
-	unsigned int i;
-	
 	atomic_set(&thread_count, THREADS);
 	atomic_set(&thread_fail, 0);
 	
-	for (i = 0; i < THREADS; i++) {
-		thread_t * thrd = thread_create(falloc, NULL, TASK, 0, "falloc", false);
+	for (unsigned int i = 0; i < THREADS; i++) {
+		thread_t *thrd = thread_create(falloc, NULL, TASK,
+		    THREAD_FLAG_NONE, "falloc2");
 		if (!thrd) {
 			TPRINTF("Could not create thread %u\n", i);
@@ -122,5 +132,6 @@
 	
 	while (atomic_get(&thread_count) > 0) {
-		TPRINTF("Threads left: %" PRIua "\n", atomic_get(&thread_count));
+		TPRINTF("Threads left: %" PRIua "\n",
+		    atomic_get(&thread_count));
 		thread_sleep(1);
 	}
Index: kernel/test/mm/slab1.c
===================================================================
--- kernel/test/mm/slab1.c	(revision 0747468d84f2b1c59f16a0b00b33c12aa2a95e3f)
+++ kernel/test/mm/slab1.c	(revision 97c76825acca82d15cb8daa0e50df4f66ffd6c0b)
@@ -155,6 +155,6 @@
 	
 	semaphore_initialize(&thr_sem, 0);
-	for (i = 0; i < THREADS; i++) {  
-		if (!(t = thread_create(slabtest, (void *) (sysarg_t) i, TASK, 0, "slabtest", false))) {
+	for (i = 0; i < THREADS; i++) {
+		if (!(t = thread_create(slabtest, (void *) (sysarg_t) i, TASK, THREAD_FLAG_NONE, "slabtest"))) {
 			TPRINTF("Could not create thread %d\n", i);
 		} else
Index: kernel/test/mm/slab2.c
===================================================================
--- kernel/test/mm/slab2.c	(revision 0747468d84f2b1c59f16a0b00b33c12aa2a95e3f)
+++ kernel/test/mm/slab2.c	(revision 97c76825acca82d15cb8daa0e50df4f66ffd6c0b)
@@ -52,6 +52,6 @@
 	void *olddata1 = NULL, *olddata2 = NULL;
 	
-	cache1 = slab_cache_create("cache1_tst", ITEM_SIZE, 0, NULL, NULL, 0);
-	cache2 = slab_cache_create("cache2_tst", ITEM_SIZE, 0, NULL, NULL, 0);
+	cache1 = slab_cache_create("test_cache1", ITEM_SIZE, 0, NULL, NULL, 0);
+	cache2 = slab_cache_create("test_cache2", ITEM_SIZE, 0, NULL, NULL, 0);
 	
 	TPRINTF("Allocating...");
@@ -210,6 +210,6 @@
 	thr_cache = slab_cache_create("thread_cache", size, 0, NULL, NULL, 0);
 	semaphore_initialize(&thr_sem,0);
-	for (i = 0; i < THREADS; i++) {  
-		if (!(t = thread_create(slabtest, NULL, TASK, 0, "slabtest", false))) {
+	for (i = 0; i < THREADS; i++) {
+		if (!(t = thread_create(slabtest, NULL, TASK, THREAD_FLAG_NONE, "slabtest"))) {
 			TPRINTF("Could not create thread %d\n", i);
 		} else
Index: kernel/test/print/print1.c
===================================================================
--- kernel/test/print/print1.c	(revision 0747468d84f2b1c59f16a0b00b33c12aa2a95e3f)
+++ kernel/test/print/print1.c	(revision 97c76825acca82d15cb8daa0e50df4f66ffd6c0b)
@@ -41,5 +41,5 @@
 	
 	TPRINTF("Testing printf(\"%%8.10s\", \"text\"):\n");
-	TPRINTF("Expected output: \"text\"\n");
+	TPRINTF("Expected output: \"    text\"\n");
 	TPRINTF("Real output:     \"%8.10s\"\n\n", "text");
 	
@@ -48,4 +48,8 @@
 	TPRINTF("Real output:     \"%8.10s\"\n\n", "very long text");
 	
+	TPRINTF("Testing printf(\"%%-*.*s\", 7, 7, \"text\"):\n");
+	TPRINTF("Expected output: \"text   \"\n");
+	TPRINTF("Real output:     \"%-*.*s\"\n\n", 7, 7, "text");
+	
 	return NULL;
 }
Index: kernel/test/synch/semaphore1.c
===================================================================
--- kernel/test/synch/semaphore1.c	(revision 0747468d84f2b1c59f16a0b00b33c12aa2a95e3f)
+++ kernel/test/synch/semaphore1.c	(revision 97c76825acca82d15cb8daa0e50df4f66ffd6c0b)
@@ -93,5 +93,6 @@
 		for (j = 0; j < (CONSUMERS + PRODUCERS) / 2; j++) {
 			for (k = 0; k < i; k++) {
-				thrd = thread_create(consumer, NULL, TASK, 0, "consumer", false);
+				thrd = thread_create(consumer, NULL, TASK,
+				    THREAD_FLAG_NONE, "consumer");
 				if (thrd)
 					thread_ready(thrd);
@@ -100,5 +101,6 @@
 			}
 			for (k = 0; k < (4 - i); k++) {
-				thrd = thread_create(producer, NULL, TASK, 0, "producer", false);
+				thrd = thread_create(producer, NULL, TASK,
+				    THREAD_FLAG_NONE, "producer");
 				if (thrd)
 					thread_ready(thrd);
Index: kernel/test/synch/semaphore2.c
===================================================================
--- kernel/test/synch/semaphore2.c	(revision 0747468d84f2b1c59f16a0b00b33c12aa2a95e3f)
+++ kernel/test/synch/semaphore2.c	(revision 97c76825acca82d15cb8daa0e50df4f66ffd6c0b)
@@ -93,5 +93,6 @@
 	TPRINTF("Creating %" PRIu32 " consumers\n", k);
 	for (i = 0; i < k; i++) {
-		thrd = thread_create(consumer, NULL, TASK, 0, "consumer", false);
+		thrd = thread_create(consumer, NULL, TASK,
+		    THREAD_FLAG_NONE, "consumer");
 		if (thrd)
 			thread_ready(thrd);
Index: kernel/test/thread/thread1.c
===================================================================
--- kernel/test/thread/thread1.c	(revision 0747468d84f2b1c59f16a0b00b33c12aa2a95e3f)
+++ kernel/test/thread/thread1.c	(revision 97c76825acca82d15cb8daa0e50df4f66ffd6c0b)
@@ -63,5 +63,6 @@
 	for (i = 0; i < THREADS; i++) {
 		thread_t *t;
-		if (!(t = thread_create(threadtest, NULL, TASK, 0, "threadtest", false))) {
+		if (!(t = thread_create(threadtest, NULL, TASK,
+		    THREAD_FLAG_NONE, "threadtest"))) {
 			TPRINTF("Could not create thread %d\n", i);
 			break;
