Index: kernel/arch/ia64/Makefile.inc
===================================================================
--- kernel/arch/ia64/Makefile.inc	(revision a1d89adda9a437fbce84276519b5bcb94321f87d)
+++ kernel/arch/ia64/Makefile.inc	(revision f2d2c7ba676ff1a37b6198b134c840dd09e1d11b)
@@ -65,6 +65,5 @@
 
 ifeq ($(MACHINE),ski)
-	ARCH_SOURCES += arch/$(KARCH)/src/ski/ski.c
-	DEFS += -DSKI
+	ARCH_SOURCES += arch/$(KARCH)/src/drivers/ski.c
 	BFD = binary
 endif
Index: kernel/arch/ia64/include/arch.h
===================================================================
--- kernel/arch/ia64/include/arch.h	(revision a1d89adda9a437fbce84276519b5bcb94321f87d)
+++ kernel/arch/ia64/include/arch.h	(revision f2d2c7ba676ff1a37b6198b134c840dd09e1d11b)
@@ -27,5 +27,5 @@
  */
 
-/** @addtogroup ia64	
+/** @addtogroup ia64
  * @{
  */
@@ -38,5 +38,5 @@
 #define LOADED_PROG_STACK_PAGES_NO 2
 
-#include <arch/ski/ski.h>
+#include <arch/drivers/ski.h>
 
 extern void arch_pre_main(void);
Index: kernel/arch/ia64/include/drivers/ski.h
===================================================================
--- kernel/arch/ia64/include/drivers/ski.h	(revision f2d2c7ba676ff1a37b6198b134c840dd09e1d11b)
+++ kernel/arch/ia64/include/drivers/ski.h	(revision f2d2c7ba676ff1a37b6198b134c840dd09e1d11b)
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2005 Jakub Jermar
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup ia64
+ * @{
+ */
+/** @file
+ */
+
+#ifndef KERN_ia64_SKI_H_
+#define KERN_ia64_SKI_H_
+
+#include <console/chardev.h>
+#include <proc/thread.h>
+
+typedef struct {
+	thread_t *thread;
+	indev_t *srlnin;
+} ski_instance_t;
+
+extern void skiout_init(void);
+
+extern ski_instance_t *skiin_init(void);
+extern void skiin_wire(ski_instance_t *, indev_t *);
+extern void ski_kbd_grab(void);
+extern void ski_kbd_release(void);
+
+#endif
+
+/** @}
+ */
Index: kernel/arch/ia64/include/ski/ski.h
===================================================================
--- kernel/arch/ia64/include/ski/ski.h	(revision a1d89adda9a437fbce84276519b5bcb94321f87d)
+++ 	(revision )
@@ -1,52 +1,0 @@
-/*
- * Copyright (c) 2005 Jakub Jermar
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/** @addtogroup ia64	
- * @{
- */
-/** @file
- */
-
-#ifndef KERN_ia64_SKI_H_
-#define KERN_ia64_SKI_H_
-
-#include <console/chardev.h>
-
-#define SKI_INIT_CONSOLE	20
-#define SKI_GETCHAR		21
-#define SKI_PUTCHAR		31
-
-extern indev_t *skiin_init(void);
-extern void skiout_init(void);
-extern void ski_kbd_grab(void);
-extern void ski_kbd_release(void);
-
-#endif
-
-/** @}
- */
Index: kernel/arch/ia64/src/drivers/ski.c
===================================================================
--- kernel/arch/ia64/src/drivers/ski.c	(revision f2d2c7ba676ff1a37b6198b134c840dd09e1d11b)
+++ kernel/arch/ia64/src/drivers/ski.c	(revision f2d2c7ba676ff1a37b6198b134c840dd09e1d11b)
@@ -0,0 +1,226 @@
+/*
+ * Copyright (c) 2005 Jakub Jermar
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup ia64
+ * @{
+ */
+/** @file
+ */
+
+#include <arch/drivers/ski.h>
+#include <console/console.h>
+#include <console/chardev.h>
+#include <sysinfo/sysinfo.h>
+#include <arch/types.h>
+#include <proc/thread.h>
+#include <synch/spinlock.h>
+#include <arch/asm.h>
+#include <arch/drivers/kbd.h>
+#include <string.h>
+#include <arch.h>
+
+#define POLL_INTERVAL  10000  /* 10 ms */
+
+#define SKI_INIT_CONSOLE  20
+#define SKI_GETCHAR       21
+#define SKI_PUTCHAR       31
+
+static void ski_putchar(outdev_t *, const wchar_t, bool);
+
+static outdev_operations_t skiout_ops = {
+	.write = ski_putchar
+};
+
+static outdev_t skiout;            /**< Ski output device. */
+static bool initialized = false;
+static bool kbd_disabled = false;
+
+/** Initialize debug console
+ *
+ * Issue SSC (Simulator System Call) to
+ * to open debug console.
+ *
+ */
+static void ski_init(void)
+{
+	if (initialized)
+		return;
+	
+	asm volatile (
+		"mov r15 = %0\n"
+		"break 0x80000\n"
+		:
+		: "i" (SKI_INIT_CONSOLE)
+		: "r15", "r8"
+	);
+	
+	initialized = true;
+}
+
+static void ski_do_putchar(const wchar_t ch)
+{
+	asm volatile (
+		"mov r15 = %[cmd]\n"
+		"mov r32 = %[ch]\n"   /* r32 is in0 */
+		"break 0x80000\n"     /* modifies r8 */
+		:
+		: [cmd] "i" (SKI_PUTCHAR), [ch] "r" (ch)
+		: "r15", "in0", "r8"
+	);
+}
+
+/** Display character on debug console
+ *
+ * Use SSC (Simulator System Call) to
+ * display character on debug console.
+ *
+ * @param dev    Character device.
+ * @param ch     Character to be printed.
+ * @param silent Whether the output should be silenced.
+ *
+ */
+static void ski_putchar(outdev_t *dev, const wchar_t ch, bool silent)
+{
+	if (!silent) {
+		if (ascii_check(ch)) {
+			if (ch == '\n')
+				ski_do_putchar('\r');
+			
+			ski_do_putchar(ch);
+		} else
+			ski_do_putchar(U_SPECIAL);
+	}
+}
+
+void skiout_init(void)
+{
+	ski_init();
+	
+	outdev_initialize("skiout", &skiout, &skiout_ops);
+	stdout = &skiout;
+	
+	sysinfo_set_item_val("fb", NULL, false);
+}
+
+/** Ask debug console if a key was pressed.
+ *
+ * Use SSC (Simulator System Call) to
+ * get character from debug console.
+ *
+ * This call is non-blocking.
+ *
+ * @return ASCII code of pressed key or 0 if no key pressed.
+ *
+ */
+static wchar_t ski_getchar(void)
+{
+	uint64_t ch;
+	
+	asm volatile (
+		"mov r15 = %1\n"
+		"break 0x80000;;\n"  /* modifies r8 */
+		"mov %0 = r8;;\n"
+		
+		: "=r" (ch)
+		: "i" (SKI_GETCHAR)
+		: "r15", "r8"
+	);
+	
+	return (wchar_t) ch;
+}
+
+/** Ask keyboard if a key was pressed. */
+static void poll_keyboard(ski_instance_t *instance)
+{
+	if (kbd_disabled)
+		return;
+	
+	wchar_t ch = ski_getchar();
+	
+	if (ch != 0)
+		indev_push_character(instance->srlnin, ch);
+}
+
+/** Kernel thread for polling keyboard. */
+static void kskipoll(void *arg)
+{
+	ski_instance_t *instance = (ski_instance_t *) arg;
+	
+	while (true) {
+		if (!silent)
+			poll_keyboard(instance);
+		
+		thread_usleep(POLL_INTERVAL);
+	}
+}
+
+ski_instance_t *skiin_init(void)
+{
+	ski_init();
+	
+	ski_instance_t *instance
+	    = malloc(sizeof(ski_instance_t), FRAME_ATOMIC);
+	
+	if (instance) {
+		instance->thread = thread_create(kskipoll, (void *) instance, TASK, 0, "kskipoll", true);
+		
+		if (!instance->thread) {
+			free(instance);
+			return NULL;
+		}
+		
+		instance->srlnin = NULL;
+	}
+	
+	return instance;
+}
+
+void skiin_wire(ski_instance_t *instance, indev_t *srlnin)
+{
+	ASSERT(instance);
+	ASSERT(srlnin);
+	
+	instance->srlnin = srlnin;
+	thread_ready(instance->thread);
+	
+	sysinfo_set_item_val("kbd", NULL, true);
+	sysinfo_set_item_val("kbd.type", NULL, KBD_SKI);
+}
+
+void ski_kbd_grab(void)
+{
+	kbd_disabled = true;
+}
+
+void ski_kbd_release(void)
+{
+	kbd_disabled = false;
+}
+
+/** @}
+ */
Index: kernel/arch/ia64/src/ia64.c
===================================================================
--- kernel/arch/ia64/src/ia64.c	(revision a1d89adda9a437fbce84276519b5bcb94321f87d)
+++ kernel/arch/ia64/src/ia64.c	(revision f2d2c7ba676ff1a37b6198b134c840dd09e1d11b)
@@ -34,5 +34,5 @@
 
 #include <arch.h>
-#include <arch/ski/ski.h>
+#include <arch/drivers/ski.h>
 #include <arch/drivers/it.h>
 #include <arch/interrupt.h>
@@ -149,9 +149,15 @@
 void arch_post_smp_init(void)
 {
-#ifdef SKI
-	indev_t *in;
-	in = skiin_init();
-	if (in)
-		srln_init(in);
+#ifdef MACHINE_ski
+	ski_instance_t *ski_instance = skiin_init();
+	if (ski_instance) {
+		srln_instance_t *srln_instance = srln_init();
+		if (srln_instance) {
+			indev_t *sink = stdin_wire();
+			indev_t *srln = srln_wire(srln_instance, sink);
+			skiin_wire(ski_instance, srln);
+		}
+	}
+	
 	skiout_init();
 #endif
@@ -162,8 +168,14 @@
 	
 #ifdef CONFIG_NS16550
-	indev_t *kbrdin_ns16550
+	ns16550_instance_t *ns16550_instance
 	    = ns16550_init((ns16550_t *) NS16550_BASE, NS16550_IRQ, NULL, NULL);
-	if (kbrdin_ns16550)
-		srln_init(kbrdin_ns16550);
+	if (ns16550_instance) {
+		srln_instance_t *srln_instance = srln_init();
+		if (srln_instance) {
+			indev_t *sink = stdin_wire();
+			indev_t *srln = srln_wire(srln_instance, sink);
+			ns16550_wire(ns16550_instance, srln);
+		}
+	}
 	
 	sysinfo_set_item_val("kbd", NULL, true);
@@ -177,7 +189,13 @@
 	
 #ifdef CONFIG_I8042
-	indev_t *kbrdin_i8042 = i8042_init((i8042_t *) I8042_BASE, IRQ_KBD);
-	if (kbrdin_i8042)
-		kbrd_init(kbrdin_i8042);
+	i8042_instance_t *i8042_instance = i8042_init((i8042_t *) I8042_BASE, IRQ_KBD);
+	if (i8042_instance) {
+		kbrd_instance_t *kbrd_instance = kbrd_init();
+		if (kbrd_instance) {
+			indev_t *sink = stdin_wire();
+			indev_t *kbrd = kbrd_wire(kbrd_instance, sink);
+			i8042_wire(i8042_instance, kbrd);
+		}
+	}
 	
 	sysinfo_set_item_val("kbd", NULL, true);
@@ -239,5 +257,5 @@
 void arch_grab_console(void)
 {
-#ifdef SKI
+#ifdef MACHINE_ski
 	ski_kbd_grab();
 #endif
@@ -249,5 +267,5 @@
 void arch_release_console(void)
 {
-#ifdef SKI
+#ifdef MACHINE_ski
 	ski_kbd_release();
 #endif
Index: kernel/arch/ia64/src/ski/ski.c
===================================================================
--- kernel/arch/ia64/src/ski/ski.c	(revision a1d89adda9a437fbce84276519b5bcb94321f87d)
+++ 	(revision )
@@ -1,210 +1,0 @@
-/*
- * Copyright (c) 2005 Jakub Jermar
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/** @addtogroup ia64
- * @{
- */
-/** @file
- */
-
-#include <arch/ski/ski.h>
-#include <console/console.h>
-#include <console/chardev.h>
-#include <sysinfo/sysinfo.h>
-#include <arch/types.h>
-#include <proc/thread.h>
-#include <synch/spinlock.h>
-#include <arch/asm.h>
-#include <arch/drivers/kbd.h>
-#include <string.h>
-#include <arch.h>
-
-static indev_t skiin;		/**< Ski input device. */
-static outdev_t skiout;		/**< Ski output device. */
-
-static bool kbd_disabled;
-
-static void ski_do_putchar(const wchar_t ch)
-{
-	asm volatile (
-		"mov r15 = %[cmd]\n"
-		"mov r32 = %[ch]\n"   /* r32 is in0 */
-		"break 0x80000\n"  /* modifies r8 */
-		:
-		: [cmd] "i" (SKI_PUTCHAR), [ch] "r" (ch)
-		: "r15", "in0", "r8"
-	);
-}
-
-/** Display character on debug console
- *
- * Use SSC (Simulator System Call) to
- * display character on debug console.
- *
- * @param d Character device.
- * @param ch Character to be printed.
- */
-static void ski_putchar(outdev_t *d, const wchar_t ch, bool silent)
-{
-	if (!silent) {
-		if (ascii_check(ch)) {
-			if (ch == '\n')
-				ski_do_putchar('\r');
-			
-			ski_do_putchar(ch);
-		} else
-			ski_do_putchar(SPECIAL);
-	}
-}
-
-static indev_operations_t skiin_ops = {
-	.poll = NULL
-};
-
-static outdev_operations_t skiout_ops = {
-	.write = ski_putchar
-};
-
-/** Ask debug console if a key was pressed.
- *
- * Use SSC (Simulator System Call) to
- * get character from debug console.
- *
- * This call is non-blocking.
- *
- * @return ASCII code of pressed key or 0 if no key pressed.
- */
-static int32_t ski_getchar(void)
-{
-	uint64_t ch;
-	
-	asm volatile (
-		"mov r15 = %1\n"
-		"break 0x80000;;\n"	/* modifies r8 */
-		"mov %0 = r8;;\n"		
-
-		: "=r" (ch)
-		: "i" (SKI_GETCHAR)
-		: "r15", "r8"
-	);
-
-	return (int32_t) ch;
-}
-
-/** Ask keyboard if a key was pressed. */
-static void poll_keyboard(void)
-{
-	char ch;
-	
-	if (kbd_disabled)
-		return;
-	ch = ski_getchar();
-	if(ch == '\r')
-		ch = '\n'; 
-	if (ch) {
-		indev_push_character(&skiin, ch);
-		return;
-	}
-}
-
-#define POLL_INTERVAL           10000           /* 10 ms */
-
-/** Kernel thread for polling keyboard. */
-static void kkbdpoll(void *arg)
-{
-	while (1) {
-		if (!silent) {
-			poll_keyboard();
-		}
-		thread_usleep(POLL_INTERVAL);
-	}
-}
-
-/** Initialize debug console
- *
- * Issue SSC (Simulator System Call) to
- * to open debug console.
- */
-static void ski_init(void)
-{
-	static bool initialized;
-
-	if (initialized)
-		return;
-	
-	asm volatile (
-		"mov r15 = %0\n"
-		"break 0x80000\n"
-		:
-		: "i" (SKI_INIT_CONSOLE)
-		: "r15", "r8"
-	);
-	
-	initialized = true;
-}
-
-indev_t *skiin_init(void)
-{
-	ski_init();
-
-	indev_initialize("skiin", &skiin, &skiin_ops);
-	thread_t *t = thread_create(kkbdpoll, NULL, TASK, 0, "kkbdpoll", true);
-	if (t)
-		thread_ready(t);
-	else
-		return NULL;
-
-	sysinfo_set_item_val("kbd", NULL, true);
-	sysinfo_set_item_val("kbd.type", NULL, KBD_SKI);
-
-	return &skiin;
-}
-
-
-void skiout_init(void)
-{
-	ski_init();
-
-	outdev_initialize("skiout", &skiout, &skiout_ops);
-	stdout = &skiout;
-
-	sysinfo_set_item_val("fb", NULL, false);
-}
-
-void ski_kbd_grab(void)
-{
-	kbd_disabled = true;
-}
-
-void ski_kbd_release(void)
-{
-	kbd_disabled = false;
-}
-
-/** @}
- */
Index: kernel/arch/ia64/src/smp/smp.c
===================================================================
--- kernel/arch/ia64/src/smp/smp.c	(revision a1d89adda9a437fbce84276519b5bcb94321f87d)
+++ kernel/arch/ia64/src/smp/smp.c	(revision f2d2c7ba676ff1a37b6198b134c840dd09e1d11b)
@@ -34,5 +34,5 @@
 
 #include <arch.h>
-#include <arch/ski/ski.h>
+#include <arch/drivers/ski.h>
 #include <arch/drivers/it.h>
 #include <arch/interrupt.h>
