Index: kernel/generic/src/console/cmd.c
===================================================================
--- kernel/generic/src/console/cmd.c	(revision 8af9950eef9c2c7dfd3ef398eb581435b1f15ac1)
+++ kernel/generic/src/console/cmd.c	(revision 36251c6d9e13b869e6fbed103955148b05ff6699)
@@ -502,5 +502,5 @@
 		cmd_initialize(basic_commands[i]);
 		if (!cmd_register(basic_commands[i]))
-			panic("could not register command %s\n", basic_commands[i]->name);
+			printf("Cannot register command %s\n", basic_commands[i]->name);
 	}
 }
Index: kernel/generic/src/console/console.c
===================================================================
--- kernel/generic/src/console/console.c	(revision 8af9950eef9c2c7dfd3ef398eb581435b1f15ac1)
+++ kernel/generic/src/console/console.c	(revision 36251c6d9e13b869e6fbed103955148b05ff6699)
@@ -168,5 +168,5 @@
 		else
 			printf("cpu: ");
-		printf("halted - no kconsole\n");
+		printf("halted (no kconsole)\n");
 		cpu_halt();
 	}
Index: kernel/generic/src/console/kconsole.c
===================================================================
--- kernel/generic/src/console/kconsole.c	(revision 8af9950eef9c2c7dfd3ef398eb581435b1f15ac1)
+++ kernel/generic/src/console/kconsole.c	(revision 36251c6d9e13b869e6fbed103955148b05ff6699)
@@ -402,9 +402,13 @@
 }
 
-/** Kernel console managing thread.
+/** Kernel console prompt.
  *
  * @param prompt Kernel console prompt (e.g kconsole/panic).
- */
-void kconsole(void *prompt)
+ * @param msg    Message to display in the beginning.
+ * @param kcon   Wait for keypress to show the prompt
+ *               and never exit.
+ *
+ */
+void kconsole(char *prompt, char *msg, bool kcon)
 {
 	cmd_info_t *cmd_info;
@@ -413,7 +417,13 @@
 
 	if (!stdin) {
-		printf("%s: no stdin\n", __func__);
+		LOG("No stdin for kernel console");
 		return;
 	}
+	
+	if (msg)
+		printf("%s", msg);
+	
+	if (kcon)
+		_getc(stdin);
 	
 	while (true) {
@@ -422,12 +432,23 @@
 		if (!len)
 			continue;
+		
 		cmd_info = parse_cmdline(cmdline, len);
 		if (!cmd_info)
 			continue;
-		if (strncmp(cmd_info->name, "exit",
-		    min(strlen(cmd_info->name), 5)) == 0)
+		
+		if ((!kcon)
+		    && (strncmp(cmd_info->name, "exit", min(strlen(cmd_info->name), 5)) == 0))
 			break;
+		
 		(void) cmd_info->func(cmd_info->argv);
 	}
+}
+
+/** Kernel console managing thread.
+ *
+ */
+void kconsole_thread(void *data)
+{
+	kconsole("kconsole", "Kernel console ready (press any key to activate)\n", true);
 }
 
Index: kernel/generic/src/cpu/cpu.c
===================================================================
--- kernel/generic/src/cpu/cpu.c	(revision 8af9950eef9c2c7dfd3ef398eb581435b1f15ac1)
+++ kernel/generic/src/cpu/cpu.c	(revision 36251c6d9e13b869e6fbed103955148b05ff6699)
@@ -87,5 +87,5 @@
 #endif /* CONFIG_SMP */
 
-	CPU = &cpus[config.cpu_active-1];
+	CPU = &cpus[config.cpu_active - 1];
 	
 	CPU->active = 1;
Index: kernel/generic/src/interrupt/interrupt.c
===================================================================
--- kernel/generic/src/interrupt/interrupt.c	(revision 8af9950eef9c2c7dfd3ef398eb581435b1f15ac1)
+++ kernel/generic/src/interrupt/interrupt.c	(revision 36251c6d9e13b869e6fbed103955148b05ff6699)
@@ -110,6 +110,8 @@
 }
 
+#ifdef CONFIG_KCONSOLE
+
 /** kconsole cmd - print all exceptions */
-static int exc_print_cmd(cmd_arg_t *argv)
+static int cmd_exc_print(cmd_arg_t *argv)
 {
 #if (IVT_ITEMS > 0)
@@ -159,12 +161,15 @@
 }
 
+
 static cmd_info_t exc_info = {
 	.name = "exc",
 	.description = "Print exception table.",
-	.func = exc_print_cmd,
+	.func = cmd_exc_print,
 	.help = NULL,
 	.argc = 0,
 	.argv = NULL
 };
+
+#endif
 
 /** Initialize generic exception handling support */
@@ -176,7 +181,9 @@
 		exc_register(i, "undef", (iroutine) exc_undef);
 
+#ifdef CONFIG_KCONSOLE
 	cmd_initialize(&exc_info);
 	if (!cmd_register(&exc_info))
-		panic("could not register command %s\n", exc_info.name);
+		printf("Cannot register command %s\n", exc_info.name);
+#endif
 }
 
Index: kernel/generic/src/lib/func.c
===================================================================
--- kernel/generic/src/lib/func.c	(revision 8af9950eef9c2c7dfd3ef398eb581435b1f15ac1)
+++ kernel/generic/src/lib/func.c	(revision 36251c6d9e13b869e6fbed103955148b05ff6699)
@@ -56,6 +56,4 @@
 	bool rundebugger = false;
 
-//      TODO test_and_set not defined on all arches
-//	if (!test_and_set(&haltstate))
 	if (!atomic_get(&haltstate)) {
 		atomic_set(&haltstate, 1);
@@ -67,10 +65,10 @@
 
 	interrupts_disable();
-#ifdef CONFIG_DEBUG
-	if (rundebugger) {
-		printf("\n");
-		kconsole("panic"); /* Run kconsole as a last resort to user */
-	}
-#endif      
+	
+#if (defined(CONFIG_DEBUG)) && (defined(CONFIG_KCONSOLE))
+	if (rundebugger)
+		kconsole("panic", "\nLast resort kernel console ready\n", false);
+#endif
+	
 	if (CPU)
 		printf("cpu%u: halted\n", CPU->id);
Index: kernel/generic/src/main/kinit.c
===================================================================
--- kernel/generic/src/main/kinit.c	(revision 8af9950eef9c2c7dfd3ef398eb581435b1f15ac1)
+++ kernel/generic/src/main/kinit.c	(revision 36251c6d9e13b869e6fbed103955148b05ff6699)
@@ -83,5 +83,8 @@
 void kinit(void *arg)
 {
-	thread_t *t;
+
+#if defined(CONFIG_SMP) || defined(CONFIG_KCONSOLE)
+	thread_t *thread;
+#endif
 
 	/*
@@ -101,21 +104,17 @@
 		 * Just a beautification.
 		 */
-		if ((t = thread_create(kmp, NULL, TASK, THREAD_FLAG_WIRED,
-		    "kmp", true))) {
-			spinlock_lock(&t->lock);
-			t->cpu = &cpus[0];
-			spinlock_unlock(&t->lock);
-			thread_ready(t);
+		thread = thread_create(kmp, NULL, TASK, THREAD_FLAG_WIRED, "kmp", true);
+		if (thread != NULL) {
+			spinlock_lock(&thread->lock);
+			thread->cpu = &cpus[0];
+			spinlock_unlock(&thread->lock);
+			thread_ready(thread);
 		} else
-			panic("thread_create/kmp\n");
-		thread_join(t);
-		thread_detach(t);
+			panic("Unable to create kmp thread\n");
+		thread_join(thread);
+		thread_detach(thread);
 	}
 #endif /* CONFIG_SMP */
-	/*
-	 * Now that all CPUs are up, we can report what we've found.
-	 */
-	cpu_list();
-
+	
 #ifdef CONFIG_SMP
 	if (config.cpu_count > 1) {
@@ -126,18 +125,17 @@
 		 */
 		for (i = 0; i < config.cpu_count; i++) {
-
-			if ((t = thread_create(kcpulb, NULL, TASK,
-			    THREAD_FLAG_WIRED, "kcpulb", true))) {
-				spinlock_lock(&t->lock);			
-				t->cpu = &cpus[i];
-				spinlock_unlock(&t->lock);
-				thread_ready(t);
+			thread = thread_create(kcpulb, NULL, TASK, THREAD_FLAG_WIRED, "kcpulb", true);
+			if (thread != NULL) {
+				spinlock_lock(&thread->lock);
+				thread->cpu = &cpus[i];
+				spinlock_unlock(&thread->lock);
+				thread_ready(thread);
 			} else
-				panic("thread_create/kcpulb\n");
+				printf("Unable to create kcpulb thread for cpu" PRIc "\n", i);
 
 		}
 	}
 #endif /* CONFIG_SMP */
-
+	
 	/*
 	 * At this point SMP, if present, is configured.
@@ -145,14 +143,17 @@
 	arch_post_smp_init();
 
-	/*
-	 * Create kernel console.
-	 */
-	t = thread_create(kconsole, (void *) "kconsole", TASK, 0, "kconsole",
-	    false);
-	if (t)
-		thread_ready(t);
-	else
-		panic("thread_create/kconsole\n");
-
+#ifdef CONFIG_KCONSOLE
+	if (stdin) {
+		/*
+		 * Create kernel console.
+		 */
+		thread = thread_create(kconsole_thread, NULL, TASK, 0, "kconsole", false);
+		if (thread != NULL)
+			thread_ready(thread);
+		else
+			printf("Unable to create kconsole thread\n");
+	}
+#endif /* CONFIG_KCONSOLE */
+	
 	interrupts_enable();
 	
@@ -165,12 +166,12 @@
 	for (i = 0; i < init.cnt; i++) {
 		if (init.tasks[i].addr % FRAME_SIZE) {
-			printf("init[%" PRIc "].addr is not frame aligned", i);
+			printf("init[%" PRIc "].addr is not frame aligned\n", i);
 			continue;
 		}
-
+		
 		int rc = program_create_from_image((void *) init.tasks[i].addr,
 		    "init-bin", &programs[i]);
-
-		if (rc == 0 && programs[i].task != NULL) {
+		
+		if ((rc == 0) && (programs[i].task != NULL)) {
 			/*
 			 * Set capabilities to init userspace tasks.
@@ -185,10 +186,8 @@
 		} else {
 			/* RAM disk image */
-			int rd = init_rd((rd_header_t *) init.tasks[i].addr,
-			    init.tasks[i].size);
+			int rd = init_rd((rd_header_t *) init.tasks[i].addr, init.tasks[i].size);
 			
 			if (rd != RE_OK)
-				printf("Init binary %" PRIc " not used, error "
-				    "code %d.\n", i, rd);
+				printf("Init binary %" PRIc " not used (error %d)\n", i, rd);
 		}
 	}
@@ -204,10 +203,16 @@
 	}
 
+#ifdef CONFIG_KCONSOLE
 	if (!stdin) {
+		printf("kinit: No stdin\nKernel alive: ");
+		
+		uint64_t i = 0;
 		while (1) {
+			printf(PRIu64 " ", i);
 			thread_sleep(1);
-			printf("kinit... ");
-		}
-	}
+			i++;
+		}
+	}
+#endif /* CONFIG_KCONSOLE */
 }
 
Index: kernel/generic/src/main/main.c
===================================================================
--- kernel/generic/src/main/main.c	(revision 8af9950eef9c2c7dfd3ef398eb581435b1f15ac1)
+++ kernel/generic/src/main/main.c	(revision 36251c6d9e13b869e6fbed103955148b05ff6699)
@@ -192,6 +192,4 @@
 	/* Keep this the first thing. */
 	the_initialize(THE);
-
-	LOG();
 	
 	version_print();
@@ -201,6 +199,6 @@
 	    config.base, config.kernel_size, config.stack_base,
 	    config.stack_size);
-	
-
+
+#ifdef CONFIG_KCONSOLE
 	/*
 	 * kconsole data structures must be initialized very early
@@ -209,4 +207,5 @@
 	 */
 	LOG_EXEC(kconsole_init());
+#endif
 	
 	/*
@@ -253,5 +252,5 @@
 		count_t i;
 		for (i = 0; i < init.cnt; i++)
-			printf("init[%" PRIc "].addr=%#" PRIp ", init[%" PRIc
+			LOG("init[%" PRIc "].addr=%#" PRIp ", init[%" PRIc
 			    "].size=%#" PRIs "\n", i, init.tasks[i].addr, i,
 			    init.tasks[i].size);
@@ -272,6 +271,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, 0, "kinit", true);
 	if (!kinit_thread)
 		panic("Can't create kinit thread\n");
Index: kernel/generic/src/mm/as.c
===================================================================
--- kernel/generic/src/mm/as.c	(revision 8af9950eef9c2c7dfd3ef398eb581435b1f15ac1)
+++ kernel/generic/src/mm/as.c	(revision 36251c6d9e13b869e6fbed103955148b05ff6699)
@@ -147,6 +147,10 @@
 	AS_KERNEL = as_create(FLAG_AS_KERNEL);
 	if (!AS_KERNEL)
-		panic("can't create kernel address space\n");
-	
+		panic("Cannot create kernel address space\n");
+	
+	/* Make sure the kernel address space
+	 * reference count never drops to zero.
+	 */
+	atomic_set(&AS_KERNEL->refcount, 1);
 }
 
@@ -177,5 +181,5 @@
 	page_table_create(flags);
 #endif
-
+	
 	return as;
 }
@@ -770,9 +774,10 @@
  * into private anonymous memory (unless it's already there).
  *
- * @param as		Address space.
- * @param flags		Flags of the area memory.
- * @param address	Address withing the area to be changed.
- *
- * @return		Zero on success or a value from @ref errno.h on failure.
+ * @param as      Address space.
+ * @param flags   Flags of the area memory.
+ * @param address Address within the area to be changed.
+ *
+ * @return Zero on success or a value from @ref errno.h on failure.
+ *
  */
 int as_area_change_flags(as_t *as, int flags, uintptr_t address)
@@ -786,5 +791,5 @@
 	index_t frame_idx;
 	count_t used_pages;
-
+	
 	/* Flags for the new memory mapping */
 	page_flags = area_flags_to_page_flags(flags);
@@ -800,5 +805,5 @@
 	}
 
-	if (area->sh_info || area->backend != &anon_backend) {
+	if ((area->sh_info) || (area->backend != &anon_backend)) {
 		/* Copying shared areas not supported yet */
 		/* Copying non-anonymous memory not supported yet */
@@ -871,4 +876,5 @@
 
 	tlb_invalidate_pages(as->asid, area->base, area->pages);
+	
 	/*
 	 * Invalidate potential software translation caches (e.g. TSB on
Index: kernel/generic/src/syscall/syscall.c
===================================================================
--- kernel/generic/src/syscall/syscall.c	(revision 8af9950eef9c2c7dfd3ef398eb581435b1f15ac1)
+++ kernel/generic/src/syscall/syscall.c	(revision 36251c6d9e13b869e6fbed103955148b05ff6699)
@@ -93,6 +93,10 @@
 static unative_t sys_debug_enable_console(void)
 {
+#ifdef CONFIG_KCONSOLE
 	arch_grab_console();
-	return 0;
+	return true;
+#else
+	return false;
+#endif
 }
 
