Index: arch/ia32/src/drivers/i8042.c
===================================================================
--- arch/ia32/src/drivers/i8042.c	(revision 4a2b52ff4fbc7a2272782d2183f8358003e7c20f)
+++ arch/ia32/src/drivers/i8042.c	(revision 481c5202d2e887d791708a8b70c6dfb8ccb36d3d)
@@ -46,8 +46,7 @@
  */
 
-#define i8042_DATA		0x60
-#define i8042_STATUS		0x64
+#define i8042_DATA			0x60
+#define i8042_STATUS			0x64
 #define i8042_BUFFER_FULL_MASK		0x01
-
 
 /** Keyboard commands. */
@@ -57,22 +56,21 @@
 
 /*
- 60   Write 8042 Command Byte: next data byte written to port 60h is
-      placed in 8042 command register.Format:
-
-     |7|6|5|4|3|2|1|0|8042 Command Byte
-      | | | | | | | `---- 1=enable output register full interrupt
-      | | | | | | `----- should be 0
-      | | | | | `------ 1=set status register system, 0=clear
-      | | | | `------- 1=override keyboard inhibit, 0=allow inhibit
-      | | | `-------- disable keyboard I/O by driving clock line low
-      | | `--------- disable auxiliary device, drives clock line low
-      | `---------- IBM scancode translation 0=AT, 1=PC/XT
-      `----------- reserved, should be 0
-*/
-
-#define i8042_SET_COMMAND 0x60
-#define i8042_COMMAND 0x49
-#define i8042_WAIT_MASK 0x02
-
+ * 60  Write 8042 Command Byte: next data byte written to port 60h is
+ *     placed in 8042 command register.Format:
+ *
+ *    |7|6|5|4|3|2|1|0|8042 Command Byte
+ *     | | | | | | | `---- 1=enable output register full interrupt
+ *     | | | | | | `----- should be 0
+ *     | | | | | `------ 1=set status register system, 0=clear
+ *     | | | | `------- 1=override keyboard inhibit, 0=allow inhibit
+ *     | | | `-------- disable keyboard I/O by driving clock line low
+ *     | | `--------- disable auxiliary device, drives clock line low
+ *     | `---------- IBM scancode translation 0=AT, 1=PC/XT
+ *     `----------- reserved, should be 0
+ */
+
+#define i8042_SET_COMMAND 	0x60
+#define i8042_COMMAND 		0x49
+#define i8042_WAIT_MASK 	0x02
 
 #define SPECIAL		'?'
@@ -88,5 +86,4 @@
 
 #define ACTIVE_READ_BUFF_SIZE 16 /*Must be power of 2*/
-
 
 __u8 active_read_buff[ACTIVE_READ_BUFF_SIZE]={0};
@@ -272,7 +269,11 @@
 {
 	exc_register(VECTOR_KBD, "i8042_interrupt", i8042_interrupt);
-	while (inb(i8042_STATUS)&i8042_WAIT_MASK);     /*Wait*/
+	while (inb(i8042_STATUS)&i8042_WAIT_MASK) {
+		/* wait */
+	}
 	outb(i8042_STATUS,i8042_SET_COMMAND);
-	while (inb(i8042_STATUS)&i8042_WAIT_MASK);     /*Wait*/
+	while (inb(i8042_STATUS)&i8042_WAIT_MASK) {
+		/* wait */
+	}
 	outb(i8042_DATA,i8042_COMMAND);
 
@@ -406,5 +407,4 @@
 }
 
-
 static __u8 active_read_buff_read(void)
 {
@@ -428,5 +428,5 @@
 
 
-static void active_readed_key_pressed(__u8 sc)
+static void active_read_key_pressed(__u8 sc)
 {
 	char *map = sc_primary_map;
@@ -497,9 +497,7 @@
 }
 
-
 static char key_read(chardev_t *d)
 {
 	char ch;	
-	
 
 	while(!(ch=active_read_buff_read()))
@@ -511,8 +509,6 @@
 			key_released(x ^ KEY_RELEASE);
 		else
-			active_readed_key_pressed(x);
+			active_read_key_pressed(x);
 	}
 	return ch;
 }
-
-
Index: arch/ia64/src/ski/ski.c
===================================================================
--- arch/ia64/src/ski/ski.c	(revision 4a2b52ff4fbc7a2272782d2183f8358003e7c20f)
+++ arch/ia64/src/ski/ski.c	(revision 481c5202d2e887d791708a8b70c6dfb8ccb36d3d)
@@ -87,15 +87,17 @@
 
 /**
-	This is blocking wrap function of ski_getchar
-	It active waits ... for using with non-stable kernel 
-*/
+ * This is a blocking wrapper for ski_getchar().
+ * To be used when the kernel crashes. 
+ */
 static char ski_getchar_blocking(chardev_t *d)
 {
-	volatile int ch;
-	while(!(ch=ski_getchar()));
-	if(ch == '\r') ch = '\n'; 
+	int ch;
+
+	while(!(ch=ski_getchar()))
+		;
+	if(ch == '\r')
+		ch = '\n'; 
 	return (char) ch;
 }
-
 
 /** Ask keyboard if a key was pressed. */
Index: arch/ia64/src/start.S
===================================================================
--- arch/ia64/src/start.S	(revision 4a2b52ff4fbc7a2272782d2183f8358003e7c20f)
+++ arch/ia64/src/start.S	(revision 481c5202d2e887d791708a8b70c6dfb8ccb36d3d)
@@ -27,5 +27,4 @@
 #
 
-
 #include <arch/register.h>
 #include <arch/mm/page.h>
@@ -33,13 +32,10 @@
 #include <mm/asid.h>
 
-
 #define RR_MASK (0xFFFFFFFF00000002)
 #define RID_SHIFT 8
 #define PS_SHIFT 2
 
-
 #define KERNEL_TRANSLATION_I 0x0010000000000661
 #define KERNEL_TRANSLATION_D 0x0010000000000661
-
 
 .section K_TEXT_START
@@ -51,5 +47,5 @@
 	.auto
 
-	#Fill TR.i and TR.d using Region Register #VRN_KERNEL
+	# Fill TR.i and TR.d using Region Register #VRN_KERNEL
 
 	movl r8=(VRN_KERNEL<<VRN_SHIFT)
@@ -61,5 +57,4 @@
 	mov rr[r8]=r9
 
-
 	movl r8=(VRN_KERNEL<<VRN_SHIFT)
 	mov cr.ifa=r8
@@ -68,8 +63,6 @@
 	movl r10=(KERNEL_TRANSLATION_I)
 	itr.i itr[r0]=r10
-
 	movl r10=(KERNEL_TRANSLATION_D)
 	itr.d dtr[r0]=r10
-
 
 	# initialize PSR
@@ -77,5 +70,5 @@
 	srlz.i
 	srlz.d
-	movl r10=(PSR_DT_MASK|PSR_RT_MASK|PSR_IT_MASK|PSR_IC_MASK)  /*Enable paging*/
+	movl r10=(PSR_DT_MASK|PSR_RT_MASK|PSR_IT_MASK|PSR_IC_MASK)  /* Enable paging */
 	mov r9=psr
 	or r10=r10,r9
@@ -86,8 +79,10 @@
 	srlz.d
 	srlz.i
-.explicit
 
-	/*Return from interupt is only the way how to fill upper half word of PSR*/
-	{rfi;;}
+	.explicit
+	/*
+	 * Return From Interupt is the only the way to fill upper half word of PSR.
+	 */
+	rfi;;
 	{nop 0;;}
 	{nop 0;;}
@@ -100,6 +95,10 @@
 
 .global paging_start
-	/*Now we are paging*/
 paging_start:
+
+	/*
+	 * Now we are paging.
+	 */
+
 	{nop 0;;}
 	{nop 0;;}
@@ -111,6 +110,4 @@
 	{nop 0;;}
 
-.auto
-	
 	# switch to register bank 1
 	bsw.1
@@ -118,9 +115,8 @@
 	# initialize register stack
 	mov ar.rsc = r0
-	movl r8=(VRN_KERNEL<<VRN_SHIFT)
+	movl r8=(VRN_KERNEL<<VRN_SHIFT) ;;
 	mov ar.bspstore = r8
 	loadrs
 
-	.explicit
 	# initialize memory stack to some sane value
 	movl r12 = stack0;;
@@ -131,9 +127,7 @@
 	movl r1 = _hardcoded_load_address	;;
 
-	
-
-	#
-	# Initialize hardcoded_* variables.
-	#
+	/*
+	 * Initialize hardcoded_* variables.
+	 */
 	movl r14 = _hardcoded_ktext_size
 	movl r15 = _hardcoded_kdata_size
@@ -147,11 +141,7 @@
 	st8 [r19] = r16
 
-
-.auto
-	
-	movl r18=main_bsp 
-	mov b1=r18
+	movl r18=main_bsp ;;
+	mov b1=r18 ;;
 	br.call.sptk.many b0=b1
-
 
 0:
Index: arch/sparc64/include/console.h
===================================================================
--- arch/sparc64/include/console.h	(revision 4a2b52ff4fbc7a2272782d2183f8358003e7c20f)
+++ arch/sparc64/include/console.h	(revision 481c5202d2e887d791708a8b70c6dfb8ccb36d3d)
@@ -30,5 +30,7 @@
 #define __sparc64_CONSOLE_H__
 
-extern void fb_sparc64_console_init(void);
+extern void kofwinput(void *arg);
+extern void ofw_sparc64_console_init(void);
+extern void standalone_sparc64_console_init(void);
 
 #endif
Index: arch/sparc64/src/console.c
===================================================================
--- arch/sparc64/src/console.c	(revision 4a2b52ff4fbc7a2272782d2183f8358003e7c20f)
+++ arch/sparc64/src/console.c	(revision 481c5202d2e887d791708a8b70c6dfb8ccb36d3d)
@@ -32,7 +32,128 @@
 #include <genarch/fb/fb.h>
 #include <arch/drivers/fb.h>
+#include <genarch/ofw/ofw.h>
+#include <console/chardev.h>
+#include <console/console.h>
+#include <arch/asm.h>
+#include <arch/register.h>
+#include <proc/thread.h>
+#include <synch/mutex.h>
 
-void fb_sparc64_console_init(void)
+static void ofw_sparc64_putchar(chardev_t *d, const char ch);
+static char ofw_sparc64_getchar(chardev_t *d);
+static void ofw_sparc64_suspend(chardev_t *d);
+static void ofw_sparc64_resume(chardev_t *d);
+
+mutex_t canwork;
+
+static volatile int ofw_console_active;
+
+static chardev_t ofw_sparc64_console;
+static chardev_operations_t ofw_sparc64_console_ops = {
+	.write = ofw_sparc64_putchar,
+	.read = ofw_sparc64_getchar,
+	.resume = ofw_sparc64_resume,
+	.suspend = ofw_sparc64_suspend
+};
+
+/** Initialize kernel console to use OpenFirmware services. */
+void ofw_sparc64_console_init(void)
 {
+	chardev_initialize("ofw_sparc64_console", &ofw_sparc64_console, &ofw_sparc64_console_ops);
+	stdin = &ofw_sparc64_console;
+	stdout = &ofw_sparc64_console;
+	mutex_initialize(&canwork);
+	ofw_console_active = 1;
+}
+
+/** Initialize kernel console to use framebuffer and keyboard directly. */
+void standalone_sparc64_console_init(void)
+{
+	ofw_console_active = 0;
+	stdin = NULL;
 	fb_init(FB_VIRT_ADDRESS, FB_X_RES, FB_Y_RES, FB_COLOR_DEPTH/8);
 }
+
+/** Write one character using OpenFirmware.
+ *
+ * @param d Character device (ignored).
+ * @param ch Character to be written.
+ */
+void ofw_sparc64_putchar(chardev_t *d, const char ch)
+{
+	pstate_reg_t pstate;
+
+	/*
+	 * 32-bit OpenFirmware depends on PSTATE.AM bit set.
+	 */	
+	pstate.value = pstate_read();
+	pstate.am = true;
+	pstate_write(pstate.value);
+
+	if (ch == '\n')
+		ofw_putchar('\r');
+	ofw_putchar(ch);
+	
+	pstate.am = false;
+	pstate_write(pstate.value);
+}
+
+/** Read one character using OpenFirmware.
+ *
+ * The call is non-blocking.
+ *
+ * @param d Character device (ignored).
+ * @return Character read or zero if no character was read.
+ */
+char ofw_sparc64_getchar(chardev_t *d)
+{
+	char ch;
+	pstate_reg_t pstate;
+
+	/*
+	 * 32-bit OpenFirmware depends on PSTATE.AM bit set.
+	 */	
+	pstate.value = pstate_read();
+	pstate.am = true;
+	pstate_write(pstate.value);
+
+	ch = ofw_getchar();
+	
+	pstate.am = false;
+	pstate_write(pstate.value);
+	
+	return ch;
+}
+
+void ofw_sparc64_suspend(chardev_t *d)
+{
+	mutex_lock(&canwork);
+}
+
+void ofw_sparc64_resume(chardev_t *d)
+{
+	mutex_unlock(&canwork);
+}
+
+/** Kernel thread for pushing characters read from OFW to input buffer.
+ *
+ * @param arg Ignored.
+ */
+void kofwinput(void *arg)
+{
+
+	while (ofw_console_active) {
+		char ch = 0;
+		
+		mutex_lock(&canwork);
+		mutex_unlock(&canwork);
+		
+		ch = ofw_sparc64_getchar(NULL);
+		if (ch) {
+			if (ch == '\r')
+				ch = '\n';
+			chardev_push_character(&ofw_sparc64_console, ch);
+		}
+		thread_usleep(25000);
+	}
+}
Index: arch/sparc64/src/sparc64.c
===================================================================
--- arch/sparc64/src/sparc64.c	(revision 4a2b52ff4fbc7a2272782d2183f8358003e7c20f)
+++ arch/sparc64/src/sparc64.c	(revision 481c5202d2e887d791708a8b70c6dfb8ccb36d3d)
@@ -37,4 +37,5 @@
 {
 	interrupts_disable();
+	ofw_sparc64_console_init();
 	trap_init();
 	tick_init();
@@ -43,5 +44,5 @@
 void arch_post_mm_init(void)
 {
-	fb_sparc64_console_init();
+	standalone_sparc64_console_init();
 }
 
@@ -52,4 +53,13 @@
 void arch_post_smp_init(void)
 {
+	thread_t *t;
+
+	/*
+         * Create thread that reads characters from OFW's input.
+         */
+	t = thread_create(kofwinput, NULL, TASK, 0);
+	if (!t)
+		panic("cannot create kofwinput\n");
+	thread_ready(t);
 }
 
