Index: kernel/arch/sparc64/Makefile.inc
===================================================================
--- kernel/arch/sparc64/Makefile.inc	(revision e2882a77555f6faf8c8ecef9941994c08e714147)
+++ kernel/arch/sparc64/Makefile.inc	(revision da747470c430a8c8b5e0ad34a1485ec2d5f3e0cb)
@@ -61,10 +61,10 @@
 CONFIG_FB = y
 
-## Compile with support for i8042 controller.
+## Compile with support for z8530 controller.
 #
 
-CONFIG_I8042 = y
-CONFIG_I8042_SUN = y
-DEFS += -DCONFIG_I8042_SUN
+CONFIG_Z8530 = y
+CONFIG_KBD_SUN = y
+DEFS += -DCONFIG_KBD_SUN
 
 ARCH_SOURCES = \
@@ -89,3 +89,3 @@
 	arch/$(ARCH)/src/ddi/ddi.c \
 	arch/$(ARCH)/src/drivers/tick.c \
-	arch/$(ARCH)/src/drivers/i8042.c
+	arch/$(ARCH)/src/drivers/kbd.c
Index: kernel/arch/sparc64/include/drivers/i8042.h
===================================================================
--- kernel/arch/sparc64/include/drivers/i8042.h	(revision e2882a77555f6faf8c8ecef9941994c08e714147)
+++ 	(revision )
@@ -1,73 +1,0 @@
-/*
- * 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_I8042_H_
-#define KERN_sparc64_I8042_H_
-
-#include <arch/types.h>
-
-#define STATUS_REG	4
-#define COMMAND_REG	4
-#define DATA_REG	6
-
-#define LAST_REG	DATA_REG
-
-extern volatile uint8_t *kbd_virt_address;
-
-static inline void i8042_data_write(uint8_t data)
-{
-	kbd_virt_address[DATA_REG] = data;
-}
-
-static inline uint8_t i8042_data_read(void)
-{
-	return kbd_virt_address[DATA_REG];
-}
-
-static inline uint8_t i8042_status_read(void)
-{
-	return kbd_virt_address[STATUS_REG];
-}
-
-static inline void i8042_command_write(uint8_t command)
-{
-	kbd_virt_address[COMMAND_REG] = command;
-}
-
-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 da747470c430a8c8b5e0ad34a1485ec2d5f3e0cb)
@@ -0,0 +1,73 @@
+/*
+ * 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_Z8530_H_
+#define KERN_sparc64_Z8530_H_
+
+#include <arch/types.h>
+
+#define STATUS_REG	4
+#define COMMAND_REG	4
+#define DATA_REG	6
+
+#define LAST_REG	DATA_REG
+
+extern volatile uint8_t *kbd_virt_address;
+
+static inline void z8530_data_write(uint8_t data)
+{
+	kbd_virt_address[DATA_REG] = data;
+}
+
+static inline uint8_t z8530_data_read(void)
+{
+	return kbd_virt_address[DATA_REG];
+}
+
+static inline uint8_t z8530_status_read(void)
+{
+	return kbd_virt_address[STATUS_REG];
+}
+
+static inline void z8530_command_write(uint8_t command)
+{
+	kbd_virt_address[COMMAND_REG] = command;
+}
+
+extern void kbd_init(void);
+
+#endif
+
+/** @}
+ */
Index: kernel/arch/sparc64/src/console.c
===================================================================
--- kernel/arch/sparc64/src/console.c	(revision e2882a77555f6faf8c8ecef9941994c08e714147)
+++ kernel/arch/sparc64/src/console.c	(revision da747470c430a8c8b5e0ad34a1485ec2d5f3e0cb)
@@ -54,10 +54,10 @@
 {
 	stdin = NULL;
+		
+	fb_init(bootinfo.screen.addr, bootinfo.screen.width, bootinfo.screen.height,
+		bootinfo.screen.bpp, bootinfo.screen.scanline, true);
 
 	if (bootinfo.keyboard.addr)
 		kbd_init();
-		
-	fb_init(bootinfo.screen.addr, bootinfo.screen.width, bootinfo.screen.height,
-		bootinfo.screen.bpp, bootinfo.screen.scanline, true);
 }
 
Index: kernel/arch/sparc64/src/drivers/i8042.c
===================================================================
--- kernel/arch/sparc64/src/drivers/i8042.c	(revision e2882a77555f6faf8c8ecef9941994c08e714147)
+++ 	(revision )
@@ -1,50 +1,0 @@
-/*
- * 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
- */
-
-#include <arch/drivers/i8042.h>
-#include <genarch/i8042/i8042.h>
-#include <arch/boot/boot.h>
-#include <arch/types.h>
-#include <arch/mm/page.h>
-
-volatile uint8_t *kbd_virt_address = NULL;
-
-void kbd_init()
-{
-	kbd_virt_address = (uint8_t *) hw_map(bootinfo.keyboard.addr, LAST_REG);
-	i8042_init();
-}
-
-/** @}
- */
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 da747470c430a8c8b5e0ad34a1485ec2d5f3e0cb)
@@ -0,0 +1,72 @@
+/*
+ * 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
+ */
+
+#ifdef CONFIG_Z8530
+#include <genarch/kbd/z8530.h>
+#endif
+#ifdef CONFIG_16650A
+#include <genarch/kbd/16650a.h>
+#endif
+#include <arch/boot/boot.h>
+#include <arch/mm/page.h>
+#include <arch/types.h>
+#include <typedefs.h>
+
+volatile uint8_t *kbd_virt_address = NULL;
+
+void kbd_init()
+{
+	size_t offset;
+	uintptr_t aligned_addr;
+
+	/*
+	 * We need to pass aligned address to hw_map().
+	 * However, the physical keyboard address can
+	 * be pretty much unaligned on some systems
+	 * (e.g. Ultra 5, Ultras 60).
+	 */
+	aligned_addr = ALIGN_DOWN(bootinfo.keyboard.addr, PAGE_SIZE);
+	offset = bootinfo.keyboard.addr - aligned_addr;
+	kbd_virt_address = (uint8_t *) hw_map(aligned_addr, offset + bootinfo.keyboard.size) + offset;
+
+#ifdef CONFIG_Z8530
+	z8530_init();
+#endif
+#ifdef CONFIG_16650A
+	16650A_init();
+#endif
+}
+
+/** @}
+ */
Index: kernel/arch/sparc64/src/mm/page.c
===================================================================
--- kernel/arch/sparc64/src/mm/page.c	(revision e2882a77555f6faf8c8ecef9941994c08e714147)
+++ kernel/arch/sparc64/src/mm/page.c	(revision da747470c430a8c8b5e0ad34a1485ec2d5f3e0cb)
@@ -47,4 +47,20 @@
 }
 
+/** Map memory-mapped device into virtual memory.
+ *
+ * So far, only DTLB is used to map devices into memory.
+ * Chances are that there will be only a limited amount of
+ * devices that the kernel itself needs to lock in DTLB.
+ *
+ * @param physaddr Physical address of the page where the
+ * 		   device is located. Must be at least
+ * 		   page-aligned.
+ * @param size Size of the device's registers. Must not
+ * 	       exceed 4M and must include extra space
+ *	       caused by the alignment.
+ *
+ * @return Virtual address of the page where the device is
+ * 	   mapped.
+ */
 uintptr_t hw_map(uintptr_t physaddr, size_t size)
 {
@@ -69,4 +85,5 @@
 	};
 	
+	ASSERT(ALIGN_UP(physaddr, PAGE_SIZE) == physaddr);
 	ASSERT(size <= 4*1024*1024);
 	
