Index: kernel/arch/sparc64/src/drivers/niagara.c
===================================================================
--- kernel/arch/sparc64/src/drivers/niagara.c	(revision d7533c7a0181109196018556b0ffcb2435426ce2)
+++ kernel/arch/sparc64/src/drivers/niagara.c	(revision 26e7d6da331e8d35b5e83880a9740de5e9e4bd99)
@@ -32,5 +32,5 @@
 /**
  * @file
- * @brief	Niagara input/output driver based on hypervisor calls.
+ * @brief Niagara input/output driver based on hypervisor calls.
  */
 
@@ -52,13 +52,13 @@
 #include <genarch/srln/srln.h>
 
-/* polling interval in miliseconds */
+/* Polling interval in miliseconds */
 #define POLL_INTERVAL  10000
 
-/* device instance */
+/* Device instance */
 static niagara_instance_t *instance = NULL;
 
-static void niagara_putchar(outdev_t *, const wchar_t, bool);
-
-/** character device operations */
+static void niagara_putchar(outdev_t *, const wchar_t);
+
+/** Character device operations */
 static outdev_operations_t niagara_ops = {
 	.write = niagara_putchar,
@@ -66,103 +66,115 @@
 };
 
-/*
+/**
  * The driver uses hypercalls to print characters to the console. Since the
  * hypercall cannot be performed from the userspace, we do this:
- * The kernel "little brother" driver (which will be present no matter what the
- * DDI architecture is - as we need the kernel part for the kconsole)
+ *
+ * The kernel "little brother" driver (which will be present no matter what
+ * the DDI architecture is -- as we need the kernel part for the kconsole)
  * defines a shared buffer. Kernel walks through the buffer (in the same thread
  * which is used for polling the keyboard) and prints any pending characters
- * to the console (using hypercalls). The userspace fb server maps this shared
- * buffer to its address space and output operation it does is performed using
- * the mapped buffer. The shared buffer definition follows.
- */
-#define OUTPUT_BUFFER_SIZE	((PAGE_SIZE) - 2 * 8)
+ * to the console (using hypercalls).
+ *
+ * The userspace fb server maps this shared buffer to its address space and
+ * output operation it does is performed using the mapped buffer. The shared
+ * buffer definition follows.
+ */
+#define OUTPUT_BUFFER_SIZE  ((PAGE_SIZE) - 2 * 8)
+
 static volatile struct {
 	uint64_t read_ptr;
 	uint64_t write_ptr;
 	char data[OUTPUT_BUFFER_SIZE];
-}
-	__attribute__ ((packed))
-	__attribute__ ((aligned(PAGE_SIZE)))
-	output_buffer;
+} __attribute__ ((packed)) __attribute__ ((aligned(PAGE_SIZE))) output_buffer;
+
+static parea_t outbuf_parea;
 
 /**
  * Analogous to the output_buffer, see the previous definition.
  */
-#define INPUT_BUFFER_SIZE	((PAGE_SIZE) - 2 * 8)
+#define INPUT_BUFFER_SIZE  ((PAGE_SIZE) - 2 * 8)
+
 static volatile struct {
 	uint64_t write_ptr;
 	uint64_t read_ptr;
 	char data[INPUT_BUFFER_SIZE];
-}
-	__attribute__ ((packed))
-	__attribute__ ((aligned(PAGE_SIZE)))
-	input_buffer;
-
-
-/** Writes a single character to the standard output. */
+} __attribute__ ((packed)) __attribute__ ((aligned(PAGE_SIZE))) input_buffer;
+
+static parea_t inbuf_parea;
+
+/** Write a single character to the standard output. */
 static inline void do_putchar(const char c) {
-	/* repeat until the buffer is non-full */
-	while (__hypercall_fast1(CONS_PUTCHAR, c) == HV_EWOULDBLOCK)
-		;
-}
-
-/** Writes a single character to the standard output. */
-static void niagara_putchar(outdev_t *dev, const wchar_t ch, bool silent)
-{
-        if (silent)
-            return;
-
-	do_putchar(ch);
-	if (ch == '\n')
-		do_putchar('\r');
-}
-
-/**
- * Function regularly called by the keyboard polling thread. Asks the
- * hypervisor whether there is any unread character. If so, it picks it up
- * and sends it to the upper layers of HelenOS.
- *
- * Apart from that, it also checks whether the userspace output driver has
- * pushed any characters to the output buffer. If so, it prints them.
- */
-static void niagara_poll(niagara_instance_t *instance)
-{
-	/* print any pending characters from the shared buffer to the console */
+	/* Repeat until the buffer is non-full */
+	while (__hypercall_fast1(CONS_PUTCHAR, c) == HV_EWOULDBLOCK);
+}
+
+/** Write a single character to the standard output. */
+static void niagara_putchar(outdev_t *dev, const wchar_t ch)
+{
+	if ((!outbuf_parea.mapped) || (console_override)) {
+		do_putchar(ch);
+		if (ch == '\n')
+			do_putchar('\r');
+	}
+}
+
+/** Poll keyboard and print pending characters.
+ *
+ * Ask the hypervisor whether there is any unread character. If so,
+ * pick it up and send it to the indev layer.
+ *
+ * Check whether the userspace output driver has pushed any
+ * characters to the output buffer and eventually print them.
+ *
+ */
+static void niagara_poll(void)
+{
+	/*
+	 * Print any pending characters from the
+	 * shared buffer to the console.
+	 */
+	
 	while (output_buffer.read_ptr != output_buffer.write_ptr) {
 		do_putchar(output_buffer.data[output_buffer.read_ptr]);
 		output_buffer.read_ptr =
-			((output_buffer.read_ptr) + 1) % OUTPUT_BUFFER_SIZE;
-	}
-
+		    ((output_buffer.read_ptr) + 1) % OUTPUT_BUFFER_SIZE;
+	}
+	
+	/*
+	 * Read character from keyboard.
+	 */
+	
 	uint64_t c;
-
-	/* read character from keyboard, send it to upper layers of HelenOS */
 	if (__hypercall_fast_ret1(0, 0, 0, 0, 0, CONS_GETCHAR, &c) == HV_EOK) {
-		if (!silent) {
-			/* kconsole active, send the character to kernel */
+		if ((!inbuf_parea.mapped) || (console_override)) {
+			/*
+			 * Kernel console is active, send
+			 * the character to kernel.
+			 */
 			indev_push_character(instance->srlnin, c);
 		} else {
-			/* kconsole inactive, send the character to uspace driver */
+			/*
+			 * Kernel console is inactive, send
+			 * the character to uspace driver.
+			 */
 			input_buffer.data[input_buffer.write_ptr] = (char) c;
 			input_buffer.write_ptr =
-				((input_buffer.write_ptr) + 1) % INPUT_BUFFER_SIZE;
+			    ((input_buffer.write_ptr) + 1) % INPUT_BUFFER_SIZE;
 		}
 	}
 }
 
-/**
- * Polling thread function.
- */
-static void kniagarapoll(void *instance) {
+/** Polling thread function.
+ *
+ */
+static void kniagarapoll(void *arg) {
 	while (true) {
-		niagara_poll(instance);
+		niagara_poll();
 		thread_usleep(POLL_INTERVAL);
 	}
 }
 
-/**
- * Initializes the input/output subsystem so that the Niagara standard
- * input/output is used.
+/** Initialize the input/output subsystem
+ *
  */
 static void niagara_init(void)
@@ -172,57 +184,54 @@
 	
 	instance = malloc(sizeof(niagara_instance_t), FRAME_ATOMIC);
-	
-	if (instance) {
-		instance->thread = thread_create(kniagarapoll, instance, TASK, 0,
-			"kniagarapoll", true);
-		
-		if (!instance->thread) {
-			free(instance);
-			instance = NULL;
-			return;
-		}
-	}
-
+	instance->thread = thread_create(kniagarapoll, NULL, TASK, 0,
+	    "kniagarapoll", true);
+	
+	if (!instance->thread) {
+		free(instance);
+		instance = NULL;
+		return;
+	}
+	
 	instance->srlnin = NULL;
-
+	
 	output_buffer.read_ptr = 0;
 	output_buffer.write_ptr = 0;
 	input_buffer.write_ptr = 0;
 	input_buffer.read_ptr = 0;
-
+	
 	/*
 	 * Set sysinfos and pareas so that the userspace counterpart of the
 	 * niagara fb and kbd driver can communicate with kernel using shared
 	 * buffers.
- 	 */
-
+	 */
+	
 	sysinfo_set_item_val("fb.kind", NULL, 5);
-
+	
 	sysinfo_set_item_val("niagara.outbuf.address", NULL,
-		KA2PA(&output_buffer));
+	    KA2PA(&output_buffer));
 	sysinfo_set_item_val("niagara.outbuf.size", NULL,
-		PAGE_SIZE);
+	    PAGE_SIZE);
 	sysinfo_set_item_val("niagara.outbuf.datasize", NULL,
-		OUTPUT_BUFFER_SIZE);
-
+	    OUTPUT_BUFFER_SIZE);
+	
 	sysinfo_set_item_val("niagara.inbuf.address", NULL,
-		KA2PA(&input_buffer));
+	    KA2PA(&input_buffer));
 	sysinfo_set_item_val("niagara.inbuf.size", NULL,
-		PAGE_SIZE);
+	    PAGE_SIZE);
 	sysinfo_set_item_val("niagara.inbuf.datasize", NULL,
-		INPUT_BUFFER_SIZE);
-
-	static parea_t outbuf_parea;
+	   INPUT_BUFFER_SIZE);
+	
 	outbuf_parea.pbase = (uintptr_t) (KA2PA(&output_buffer));
 	outbuf_parea.frames = 1;
 	outbuf_parea.unpriv = false;
+	outbuf_parea.mapped = false;
 	ddi_parea_register(&outbuf_parea);
-
-	static parea_t inbuf_parea;
+	
 	inbuf_parea.pbase = (uintptr_t) (KA2PA(&input_buffer));
 	inbuf_parea.frames = 1;
 	inbuf_parea.unpriv = false;
+	inbuf_parea.mapped = false;
 	ddi_parea_register(&inbuf_parea);
-
+	
 	outdev_t *niagara_dev = malloc(sizeof(outdev_t), FRAME_ATOMIC);
 	outdev_initialize("niagara_dev", niagara_dev, &niagara_ops);
@@ -230,11 +239,11 @@
 }
 
-/**
- * A public function which initializes input from the Niagara console.
+/** Initialize input from the Niagara console.
+ *
  */
 niagara_instance_t *niagarain_init(void)
 {
 	niagara_init();
-
+	
 	if (instance) {
 		srln_instance_t *srln_instance = srln_init();
@@ -242,10 +251,10 @@
 			indev_t *sink = stdin_wire();
 			indev_t *srln = srln_wire(srln_instance, sink);
-
-			// wire std. input to niagara
+			
 			instance->srlnin = srln;
 			thread_ready(instance->thread);
 		}
 	}
+	
 	return instance;
 }
