Index: kernel/arch/amd64/Makefile.inc
===================================================================
--- kernel/arch/amd64/Makefile.inc	(revision da747470c430a8c8b5e0ad34a1485ec2d5f3e0cb)
+++ kernel/arch/amd64/Makefile.inc	(revision 287920fbf506e950a6b1035b8520eeaf673338bf)
@@ -62,6 +62,4 @@
 
 CONFIG_I8042 = y
-CONFIG_I8042_PC = y
-DEFS += -DCONFIG_I8042_PC
 
 ## Accepted configuration directives
Index: kernel/arch/amd64/src/amd64.c
===================================================================
--- kernel/arch/amd64/src/amd64.c	(revision da747470c430a8c8b5e0ad34a1485ec2d5f3e0cb)
+++ kernel/arch/amd64/src/amd64.c	(revision 287920fbf506e950a6b1035b8520eeaf673338bf)
@@ -27,5 +27,5 @@
  */
 
- /** @addtogroup amd64
+/** @addtogroup amd64
  * @{
  */
@@ -42,5 +42,5 @@
 #include <arch/drivers/ega.h>
 #include <arch/drivers/vesa.h>
-#include <genarch/i8042/i8042.h>
+#include <genarch/kbd/i8042.h>
 #include <arch/drivers/i8254.h>
 #include <arch/drivers/i8259.h>
@@ -209,5 +209,4 @@
 }
 
- /** @}
- */
-
+/** @}
+ */
Index: kernel/arch/ia32/Makefile.inc
===================================================================
--- kernel/arch/ia32/Makefile.inc	(revision da747470c430a8c8b5e0ad34a1485ec2d5f3e0cb)
+++ kernel/arch/ia32/Makefile.inc	(revision 287920fbf506e950a6b1035b8520eeaf673338bf)
@@ -81,6 +81,4 @@
 
 CONFIG_I8042 = y
-CONFIG_I8042_PC = y
-DEFS += -DCONFIG_I8042_PC
 
 ## Accepted configuration directives
Index: kernel/arch/ia32/src/ia32.c
===================================================================
--- kernel/arch/ia32/src/ia32.c	(revision da747470c430a8c8b5e0ad34a1485ec2d5f3e0cb)
+++ kernel/arch/ia32/src/ia32.c	(revision 287920fbf506e950a6b1035b8520eeaf673338bf)
@@ -42,5 +42,5 @@
 #include <arch/drivers/ega.h>
 #include <arch/drivers/vesa.h>
-#include <genarch/i8042/i8042.h>
+#include <genarch/kbd/i8042.h>
 #include <arch/drivers/i8254.h>
 #include <arch/drivers/i8259.h>
Index: kernel/arch/sparc64/Makefile.inc
===================================================================
--- kernel/arch/sparc64/Makefile.inc	(revision da747470c430a8c8b5e0ad34a1485ec2d5f3e0cb)
+++ kernel/arch/sparc64/Makefile.inc	(revision 287920fbf506e950a6b1035b8520eeaf673338bf)
@@ -65,6 +65,5 @@
 
 CONFIG_Z8530 = y
-CONFIG_KBD_SUN = y
-DEFS += -DCONFIG_KBD_SUN
+DEFS += -DCONFIG_Z8530
 
 ARCH_SOURCES = \
Index: kernel/arch/sparc64/include/drivers/kbd.h
===================================================================
--- kernel/arch/sparc64/include/drivers/kbd.h	(revision 287920fbf506e950a6b1035b8520eeaf673338bf)
+++ kernel/arch/sparc64/include/drivers/kbd.h	(revision 287920fbf506e950a6b1035b8520eeaf673338bf)
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2006 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 sparc64	
+ * @{
+ */
+/** @file
+ */
+
+#ifndef KERN_sparc64_KBD_H_
+#define KERN_sparc64_KBD_H_
+
+#include <arch/types.h>
+
+extern volatile uint8_t *kbd_virt_address;
+
+extern void kbd_init(void);
+
+#endif
+
+/** @}
+ */
Index: kernel/arch/sparc64/include/drivers/z8530.h
===================================================================
--- kernel/arch/sparc64/include/drivers/z8530.h	(revision da747470c430a8c8b5e0ad34a1485ec2d5f3e0cb)
+++ kernel/arch/sparc64/include/drivers/z8530.h	(revision 287920fbf506e950a6b1035b8520eeaf673338bf)
@@ -37,4 +37,5 @@
 
 #include <arch/types.h>
+#include <arch/drivers/kbd.h>
 
 #define STATUS_REG	4
@@ -43,6 +44,4 @@
 
 #define LAST_REG	DATA_REG
-
-extern volatile uint8_t *kbd_virt_address;
 
 static inline void z8530_data_write(uint8_t data)
@@ -66,6 +65,4 @@
 }
 
-extern void kbd_init(void);
-
 #endif
 
Index: kernel/arch/sparc64/src/console.c
===================================================================
--- kernel/arch/sparc64/src/console.c	(revision da747470c430a8c8b5e0ad34a1485ec2d5f3e0cb)
+++ kernel/arch/sparc64/src/console.c	(revision 287920fbf506e950a6b1035b8520eeaf673338bf)
@@ -38,6 +38,13 @@
 #include <genarch/fb/fb.h>
 #include <arch/drivers/fb.h>
-#include <arch/drivers/i8042.h>
-#include <genarch/i8042/i8042.h>
+
+#include <arch/drivers/kbd.h>
+#ifdef CONFIG_Z8530
+#include <genarch/kbd/z8530.h>
+#endif
+#ifdef CONFIG_16550A
+#include <genarch/kbd/16550a.h>
+#endif
+
 #include <console/chardev.h>
 #include <console/console.h>
@@ -72,5 +79,10 @@
 		
 	while (1) {
-		i8042_poll();		
+#ifdef CONFIG_Z8530
+		z8530_poll();
+#endif
+#ifdef CONFIG_16550A
+		16550a_poll();
+#endif
 		thread_usleep(KEYBOARD_POLL_PAUSE);
 	}
Index: kernel/arch/sparc64/src/drivers/kbd.c
===================================================================
--- kernel/arch/sparc64/src/drivers/kbd.c	(revision da747470c430a8c8b5e0ad34a1485ec2d5f3e0cb)
+++ kernel/arch/sparc64/src/drivers/kbd.c	(revision 287920fbf506e950a6b1035b8520eeaf673338bf)
@@ -33,4 +33,5 @@
  */
 
+#include <arch/drivers/kbd.h>
 #ifdef CONFIG_Z8530
 #include <genarch/kbd/z8530.h>
@@ -39,8 +40,10 @@
 #include <genarch/kbd/16650a.h>
 #endif
+
 #include <arch/boot/boot.h>
 #include <arch/mm/page.h>
 #include <arch/types.h>
 #include <typedefs.h>
+#include <align.h>
 
 volatile uint8_t *kbd_virt_address = NULL;
@@ -50,4 +53,7 @@
 	size_t offset;
 	uintptr_t aligned_addr;
+
+	/* FIXME: supply value read from OpenFirmware */
+	bootinfo.keyboard.size = 8;
 
 	/*
Index: kernel/arch/sparc64/src/mm/tlb.c
===================================================================
--- kernel/arch/sparc64/src/mm/tlb.c	(revision da747470c430a8c8b5e0ad34a1485ec2d5f3e0cb)
+++ kernel/arch/sparc64/src/mm/tlb.c	(revision 287920fbf506e950a6b1035b8520eeaf673338bf)
@@ -48,7 +48,4 @@
 #include <symtab.h>
 
-#include <arch/drivers/fb.h>
-#include <arch/drivers/i8042.h>
-
 char *context_encoding[] = {
 	"Primary",
@@ -61,6 +58,5 @@
 {
 	/*
-	 * TLBs are actually initialized by
-	 * take_over_tlb_and_tt() early
+	 * TLBs are actually initialized early
 	 * in start.S.
 	 */
Index: kernel/genarch/Makefile.inc
===================================================================
--- kernel/genarch/Makefile.inc	(revision da747470c430a8c8b5e0ad34a1485ec2d5f3e0cb)
+++ kernel/genarch/Makefile.inc	(revision 287920fbf506e950a6b1035b8520eeaf673338bf)
@@ -68,14 +68,12 @@
 ifeq ($(CONFIG_I8042),y)
 	GENARCH_SOURCES += \
-		genarch/src/i8042/i8042.c
-		
-	ifeq ($(CONFIG_I8042_PC),y)
-		GENARCH_SOURCES += \
-			genarch/src/i8042/scanc_pc.c
-	endif
-	ifeq ($(CONFIG_I8042_SUN),y)
-		GENARCH_SOURCES += \
-			genarch/src/i8042/scanc_sun.c
-	endif
-	
+		genarch/src/kbd/i8042.c \
+		genarch/src/kbd/scanc_pc.c
 endif
+
+## z8530 controller
+ifeq ($(CONFIG_Z8530),y)
+	GENARCH_SOURCES += \
+		genarch/src/kbd/z8530.c \
+		genarch/src/kbd/scanc_sun.c
+endif
Index: kernel/genarch/include/kbd/i8042.h
===================================================================
--- kernel/genarch/include/kbd/i8042.h	(revision da747470c430a8c8b5e0ad34a1485ec2d5f3e0cb)
+++ kernel/genarch/include/kbd/i8042.h	(revision 287920fbf506e950a6b1035b8520eeaf673338bf)
@@ -36,11 +36,4 @@
 #define KERN_I8042_H_
 
-#include <genarch/kbd/scanc_pc.h>
-
-#define SPECIAL		'?'
-
-extern char sc_primary_map[];
-extern char sc_secondary_map[];
-
 extern void i8042_init(void);
 extern void i8042_poll(void);
Index: kernel/genarch/include/kbd/scanc.h
===================================================================
--- kernel/genarch/include/kbd/scanc.h	(revision 287920fbf506e950a6b1035b8520eeaf673338bf)
+++ kernel/genarch/include/kbd/scanc.h	(revision 287920fbf506e950a6b1035b8520eeaf673338bf)
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2006 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 genarch	
+ * @{
+ */
+/**
+ * @file
+ */
+
+#ifndef KERN_SCANC_H_
+#define KERN_SCANC_H_
+
+#define SPECIAL         '?'
+
+extern char sc_primary_map[];
+extern char sc_secondary_map[];
+
+#endif
+
+/** @}
+ */
Index: kernel/genarch/include/kbd/z8530.h
===================================================================
--- kernel/genarch/include/kbd/z8530.h	(revision da747470c430a8c8b5e0ad34a1485ec2d5f3e0cb)
+++ kernel/genarch/include/kbd/z8530.h	(revision 287920fbf506e950a6b1035b8520eeaf673338bf)
@@ -38,11 +38,4 @@
 #define KERN_Z8530_H_
 
-#include <genarch/kbd/scanc_sun.h>
-
-#define SPECIAL		'?'
-
-extern char sc_primary_map[];
-extern char sc_secondary_map[];
-
 extern void z8530_init(void);
 extern void z8530_poll(void);
Index: kernel/genarch/src/kbd/i8042.c
===================================================================
--- kernel/genarch/src/kbd/i8042.c	(revision da747470c430a8c8b5e0ad34a1485ec2d5f3e0cb)
+++ kernel/genarch/src/kbd/i8042.c	(revision 287920fbf506e950a6b1035b8520eeaf673338bf)
@@ -37,5 +37,7 @@
  */
 
-#include <genarch/i8042/i8042.h>
+#include <genarch/kbd/i8042.h>
+#include <genarch/kbd/scanc.h>
+#include <genarch/kbd/scanc_pc.h>
 #include <arch/drivers/i8042.h>
 #include <arch/interrupt.h>
@@ -79,9 +81,4 @@
 #define KEY_RELEASE	0x80
 
-/**
- * These codes read from i8042 data register are silently ignored.
- */
-#define IGNORE_CODE	0x7f
-
 static void key_released(uint8_t sc);
 static void key_pressed(uint8_t sc);
@@ -391,10 +388,8 @@
 			;
 		x = i8042_data_read();
-		if (x != IGNORE_CODE) {
-			if (x & KEY_RELEASE)
-				key_released(x ^ KEY_RELEASE);
-			else
-				active_read_key_pressed(x);
-		}
+		if (x & KEY_RELEASE)
+			key_released(x ^ KEY_RELEASE);
+		else
+			active_read_key_pressed(x);
 	}
 	return ch;
@@ -411,10 +406,8 @@
 	while (((x = i8042_status_read() & i8042_BUFFER_FULL_MASK))) {
 		x = i8042_data_read();
-		if (x != IGNORE_CODE) {
-			if (x & KEY_RELEASE)
-				key_released(x ^ KEY_RELEASE);
-			else
-				key_pressed(x);
-		}
+		if (x & KEY_RELEASE)
+			key_released(x ^ KEY_RELEASE);
+		else
+			key_pressed(x);
 	}
 }
@@ -422,3 +415,2 @@
 /** @}
  */
-
Index: kernel/genarch/src/kbd/scanc_pc.c
===================================================================
--- kernel/genarch/src/kbd/scanc_pc.c	(revision da747470c430a8c8b5e0ad34a1485ec2d5f3e0cb)
+++ kernel/genarch/src/kbd/scanc_pc.c	(revision 287920fbf506e950a6b1035b8520eeaf673338bf)
@@ -35,5 +35,5 @@
  */
 
-#include <genarch/i8042/i8042.h>
+#include <genarch/kbd/scanc.h>
 
 /** Primary meaning of scancodes. */
Index: kernel/genarch/src/kbd/scanc_sun.c
===================================================================
--- kernel/genarch/src/kbd/scanc_sun.c	(revision da747470c430a8c8b5e0ad34a1485ec2d5f3e0cb)
+++ kernel/genarch/src/kbd/scanc_sun.c	(revision 287920fbf506e950a6b1035b8520eeaf673338bf)
@@ -35,5 +35,5 @@
  */
 
-#include <genarch/i8042/i8042.h>
+#include <genarch/kbd/scanc.h>
 
 /** Primary meaning of scancodes. */
Index: kernel/genarch/src/kbd/z8530.c
===================================================================
--- kernel/genarch/src/kbd/z8530.c	(revision 287920fbf506e950a6b1035b8520eeaf673338bf)
+++ kernel/genarch/src/kbd/z8530.c	(revision 287920fbf506e950a6b1035b8520eeaf673338bf)
@@ -0,0 +1,430 @@
+/*
+ * Copyright (C) 2001-2004 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 genarch	
+ * @{
+ */
+/**
+ * @file
+ * @brief	Zilog 8530 serial port / keyboard driver.
+ *
+ * Note that this file is derived from the i8042.c.
+ * The i8042 driver could be persuaded to control
+ * the z8530 at least in the polling mode.
+ * As a result, this file may contain inaccurate
+ * and z8530-irrelevant constants, code and comments.
+ * Still it miraculously works.
+ */
+
+#include <genarch/kbd/z8530.h>
+#include <genarch/kbd/scanc.h>
+#include <genarch/kbd/scanc_sun.h>
+#include <arch/drivers/z8530.h>
+#include <arch/interrupt.h>
+#include <cpu.h>
+#include <arch/asm.h>
+#include <arch.h>
+#include <synch/spinlock.h>
+#include <typedefs.h>
+#include <console/chardev.h>
+#include <console/console.h>
+#include <macros.h>
+#include <interrupt.h>
+
+/* Keyboard commands. */
+#define KBD_ENABLE	0xf4
+#define KBD_DISABLE	0xf5
+#define KBD_ACK		0xfa
+
+/*
+ * 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 z8530_SET_COMMAND 	0x60
+#define z8530_COMMAND 		0x69
+
+#define z8530_BUFFER_FULL_MASK	0x01
+#define z8530_WAIT_MASK 	0x02
+#define z8530_MOUSE_DATA        0x20
+
+#define KEY_RELEASE	0x80
+
+/*
+ * These codes read from z8530 data register are silently ignored.
+ */
+#define IGNORE_CODE	0x7f		/* all keys up */
+
+static void key_released(uint8_t sc);
+static void key_pressed(uint8_t sc);
+static char key_read(chardev_t *d);
+
+#define PRESSED_SHIFT		(1<<0)
+#define PRESSED_CAPSLOCK	(1<<1)
+#define LOCKED_CAPSLOCK		(1<<0)
+
+#define ACTIVE_READ_BUFF_SIZE 16 	/* Must be power of 2 */
+
+static uint8_t active_read_buff[ACTIVE_READ_BUFF_SIZE];
+
+SPINLOCK_INITIALIZE(keylock);		/**< keylock protects keyflags and lockflags. */
+static volatile int keyflags;		/**< Tracking of multiple keypresses. */
+static volatile int lockflags;		/**< Tracking of multiple keys lockings. */
+
+static void z8530_suspend(chardev_t *);
+static void z8530_resume(chardev_t *);
+
+static chardev_t kbrd;
+static chardev_operations_t ops = {
+	.suspend = z8530_suspend,
+	.resume = z8530_resume,
+	.read = key_read
+};
+
+static void z8530_interrupt(int n, istate_t *istate);
+static void z8530_wait(void);
+
+static iroutine oldvector;
+/** Initialize keyboard and service interrupts using kernel routine */
+void z8530_grab(void)
+{
+	oldvector = exc_register(VECTOR_KBD, "z8530_interrupt", (iroutine) z8530_interrupt);
+	z8530_wait();
+	z8530_command_write(z8530_SET_COMMAND);
+	z8530_wait();
+	z8530_data_write(z8530_COMMAND);
+	z8530_wait();
+}
+/** Resume the former interrupt vector */
+void z8530_release(void)
+{
+	if (oldvector)
+		exc_register(VECTOR_KBD, "user_interrupt", oldvector);
+}
+
+/** Initialize z8530. */
+void z8530_init(void)
+{
+	int i;
+
+	z8530_grab();
+        /* Prevent user from accidentaly releasing calling z8530_resume
+	 * and disabling keyboard 
+	 */
+	oldvector = NULL; 
+
+	trap_virtual_enable_irqs(1<<IRQ_KBD);
+	chardev_initialize("z8530_kbd", &kbrd, &ops);
+	stdin = &kbrd;
+
+	/*
+	 * Clear input buffer.
+	 * Number of iterations is limited to prevent infinite looping.
+	 */
+	for (i = 0; (z8530_status_read() & z8530_BUFFER_FULL_MASK) && i < 100; i++) {
+		z8530_data_read();
+	}  
+}
+
+/** Process z8530 interrupt.
+ *
+ * @param n Interrupt vector.
+ * @param istate Interrupted state.
+ */
+void z8530_interrupt(int n, istate_t *istate)
+{
+	uint8_t x;
+	uint8_t status;
+
+	while (((status=z8530_status_read()) & z8530_BUFFER_FULL_MASK)) {
+		x = z8530_data_read();
+
+		if ((status & z8530_MOUSE_DATA))
+			continue;
+
+		if (x & KEY_RELEASE)
+			key_released(x ^ KEY_RELEASE);
+		else
+			key_pressed(x);
+	}
+	trap_virtual_eoi();
+}
+
+/** Wait until the controller reads its data. */
+void z8530_wait(void) {
+	while (z8530_status_read() & z8530_WAIT_MASK) {
+		/* wait */
+	}
+}
+
+/** Process release of key.
+ *
+ * @param sc Scancode of the key being released.
+ */
+void key_released(uint8_t sc)
+{
+	spinlock_lock(&keylock);
+	switch (sc) {
+	    case SC_LSHIFT:
+	    case SC_RSHIFT:
+		keyflags &= ~PRESSED_SHIFT;
+		break;
+	    case SC_CAPSLOCK:
+		keyflags &= ~PRESSED_CAPSLOCK;
+		if (lockflags & LOCKED_CAPSLOCK)
+			lockflags &= ~LOCKED_CAPSLOCK;
+		else
+			lockflags |= LOCKED_CAPSLOCK;
+		break;
+	    default:
+		break;
+	}
+	spinlock_unlock(&keylock);
+}
+
+/** Process keypress.
+ *
+ * @param sc Scancode of the key being pressed.
+ */
+void key_pressed(uint8_t sc)
+{
+	char *map = sc_primary_map;
+	char ascii = sc_primary_map[sc];
+	bool shift, capslock;
+	bool letter = false;
+
+	spinlock_lock(&keylock);
+	switch (sc) {
+	case SC_LSHIFT:
+	case SC_RSHIFT:
+	    	keyflags |= PRESSED_SHIFT;
+		break;
+	case SC_CAPSLOCK:
+		keyflags |= PRESSED_CAPSLOCK;
+		break;
+	case SC_SPEC_ESCAPE:
+		break;
+	case SC_LEFTARR:
+		chardev_push_character(&kbrd, 0x1b);
+		chardev_push_character(&kbrd, 0x5b);
+		chardev_push_character(&kbrd, 0x44);
+		break;
+	case SC_RIGHTARR:
+		chardev_push_character(&kbrd, 0x1b);
+		chardev_push_character(&kbrd, 0x5b);
+		chardev_push_character(&kbrd, 0x43);
+		break;
+	case SC_UPARR:
+		chardev_push_character(&kbrd, 0x1b);
+		chardev_push_character(&kbrd, 0x5b);
+		chardev_push_character(&kbrd, 0x41);
+		break;
+	case SC_DOWNARR:
+		chardev_push_character(&kbrd, 0x1b);
+		chardev_push_character(&kbrd, 0x5b);
+		chardev_push_character(&kbrd, 0x42);
+		break;
+	case SC_HOME:
+		chardev_push_character(&kbrd, 0x1b);
+		chardev_push_character(&kbrd, 0x4f);
+		chardev_push_character(&kbrd, 0x48);
+		break;
+	case SC_END:
+		chardev_push_character(&kbrd, 0x1b);
+		chardev_push_character(&kbrd, 0x4f);
+		chardev_push_character(&kbrd, 0x46);
+		break;
+	case SC_DELETE:
+		chardev_push_character(&kbrd, 0x1b);
+		chardev_push_character(&kbrd, 0x5b);
+		chardev_push_character(&kbrd, 0x33);
+		chardev_push_character(&kbrd, 0x7e);
+		break;
+	default:
+	    	letter = is_lower(ascii);
+		capslock = (keyflags & PRESSED_CAPSLOCK) || (lockflags & LOCKED_CAPSLOCK);
+		shift = keyflags & PRESSED_SHIFT;
+		if (letter && capslock)
+			shift = !shift;
+		if (shift)
+			map = sc_secondary_map;
+		chardev_push_character(&kbrd, map[sc]);
+		break;
+	}
+	spinlock_unlock(&keylock);
+}
+
+/* Called from getc(). */
+void z8530_resume(chardev_t *d)
+{
+}
+
+/* Called from getc(). */
+void z8530_suspend(chardev_t *d)
+{
+}
+
+static uint8_t active_read_buff_read(void)
+{
+	static int i=0;
+	i &= (ACTIVE_READ_BUFF_SIZE-1);
+	if(!active_read_buff[i]) {
+		return 0;
+	}
+	return active_read_buff[i++];
+}
+
+static void active_read_buff_write(uint8_t ch)
+{
+	static int i=0;
+	active_read_buff[i] = ch;
+	i++;
+	i &= (ACTIVE_READ_BUFF_SIZE-1);
+	active_read_buff[i]=0;
+}
+
+
+static void active_read_key_pressed(uint8_t sc)
+{
+	char *map = sc_primary_map;
+	char ascii = sc_primary_map[sc];
+	bool shift, capslock;
+	bool letter = false;
+
+	/*spinlock_lock(&keylock);*/
+	switch (sc) {
+	case SC_LSHIFT:
+	case SC_RSHIFT:
+	    	keyflags |= PRESSED_SHIFT;
+		break;
+	case SC_CAPSLOCK:
+		keyflags |= PRESSED_CAPSLOCK;
+		break;
+	case SC_SPEC_ESCAPE:
+		break;
+	case SC_LEFTARR:
+		active_read_buff_write(0x1b);
+		active_read_buff_write(0x5b);
+		active_read_buff_write(0x44);
+		break;
+	case SC_RIGHTARR:
+		active_read_buff_write(0x1b);
+		active_read_buff_write(0x5b);
+		active_read_buff_write(0x43);
+		break;
+	case SC_UPARR:
+		active_read_buff_write(0x1b);
+		active_read_buff_write(0x5b);
+		active_read_buff_write(0x41);
+		break;
+	case SC_DOWNARR:
+		active_read_buff_write(0x1b);
+		active_read_buff_write(0x5b);
+		active_read_buff_write(0x42);
+		break;
+	case SC_HOME:
+		active_read_buff_write(0x1b);
+		active_read_buff_write(0x4f);
+		active_read_buff_write(0x48);
+		break;
+	case SC_END:
+		active_read_buff_write(0x1b);
+		active_read_buff_write(0x4f);
+		active_read_buff_write(0x46);
+		break;
+	case SC_DELETE:
+		active_read_buff_write(0x1b);
+		active_read_buff_write(0x5b);
+		active_read_buff_write(0x33);
+		active_read_buff_write(0x7e);
+		break;
+	default:
+	    	letter = is_lower(ascii);
+		capslock = (keyflags & PRESSED_CAPSLOCK) || (lockflags & LOCKED_CAPSLOCK);
+		shift = keyflags & PRESSED_SHIFT;
+		if (letter && capslock)
+			shift = !shift;
+		if (shift)
+			map = sc_secondary_map;
+		active_read_buff_write(map[sc]);
+		break;
+	}
+	/*spinlock_unlock(&keylock);*/
+
+}
+
+static char key_read(chardev_t *d)
+{
+	char ch;	
+
+	while(!(ch = active_read_buff_read())) {
+		uint8_t x;
+		while (!(z8530_status_read() & z8530_BUFFER_FULL_MASK))
+			;
+		x = z8530_data_read();
+		if (x != IGNORE_CODE) {
+			if (x & KEY_RELEASE)
+				key_released(x ^ KEY_RELEASE);
+			else
+				active_read_key_pressed(x);
+		}
+	}
+	return ch;
+}
+
+/** Poll for key press and release events.
+ *
+ * This function can be used to implement keyboard polling.
+ */
+void z8530_poll(void)
+{
+	uint8_t x;
+
+	while (((x = z8530_status_read() & z8530_BUFFER_FULL_MASK))) {
+		x = z8530_data_read();
+		if (x != IGNORE_CODE) {
+			if (x & KEY_RELEASE)
+				key_released(x ^ KEY_RELEASE);
+			else
+				key_pressed(x);
+		}
+	}
+}
+
+/** @}
+ */
